SQL Practice
SQL Practice
For a user, the events which are at an interval of less than or equal to 30 minutes, belong to the
same session ID. figure out those session and event iDs for every user.
select a.request_at,
ROUND(((SUM(CASE WHEN LOWER(a.Status) LIKE 'cancelled%' THEN 1.000 ELSE 0 END))
/ COUNT(a.id)), 2) AS "Cancellation Rate"
from Trips a join users b
on a.client_id= b.users_id
where b.banned = 'No'
group by request_at;
3) median salary of employee
SELECT
Employee.Id, Employee.Company, Employee.Salary
FROM
Employee,
Employee alias
WHERE
Employee.Company = alias.Company
GROUP BY Employee.Company , Employee.Salary
HAVING SUM(CASE
WHEN Employee.Salary = alias.Salary THEN 1
ELSE 0
END) >= ABS(SUM(SIGN(Employee.Salary - alias.Salary)))
ORDER BY Employee.Id
;