IF Statements

  • 0

    I recently learned about MySQL's IF statements and thought I would share this

    SELECT Request_at AS 'Day',
            ROUND(cancelled / (completed + cancelled), 2) AS 'Cancellation Rate'
                SELECT SUM(IF(Status LIKE 'cancelled%', 1, 0)) AS cancelled,
                        SUM(IF(Status LIKE 'completed', 1, 0)) AS completed,
                    FROM Trips
                    INNER JOIN Users
                        ON Users_Id = Client_Id
                            WHERE Request_at BETWEEN '2013-10-01' AND '2013-10-03'
                                AND Banned = 'No'
                    GROUP BY Request_at) 
        AS relevant_trips;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.