본문 바로가기

SQL101

leetcode 511. Game Play Analysis I 1 2 3 4 # Write your MySQL query statement below select player_id, min(event_date) as first_login from Activity group by player_id cs 2022. 3. 31.
leetcode 1965. Employees With Missing Information 1 2 3 4 5 6 7 8 select employee_id from( select employee_id from Employees union all select employee_id from Salaries )t group by employee_id having count(*)=1 order by 1 Colored by Color Scripter cs 2022. 3. 31.
leetcode 1179. Reformat Department Table 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # Write your MySQL query statement below SELECT id, SUM(CASE WHEN month = 'jan' THEN revenue END) AS Jan_Revenue, SUM(CASE WHEN month = 'feb' THEN revenue END) AS Feb_Revenue, SUM(CASE WHEN month = 'mar' THEN revenue END) AS Mar_Revenue, SUM(CASE WHEN month = 'apr' THEN revenue END) AS Apr_Revenue, SUM(CASE WHEN month = 'may' THEN revenue END) AS May_Revenu.. 2022. 3. 31.
leetcode 1407. Top Travellers 1 2 3 4 5 6 # Write your MySQL query statement below select u.name, IFNULL(sum(r.distance), 0) as travelled_distance from Users u left join Rides r on u.id=r.user_id group by r.user_id order by 2 desc, 1 asc Colored by Color Scripter cs 2022. 3. 31.
leetcode 1890. The Latest Login in 2020 1 2 3 4 5 6 7 # Write your MySQL query statement below select user_id, max(time_stamp) as last_stamp from Logins where 1=1 and time_stamp>='2020-01-01' and time_stamp 2022. 3. 30.
leetcode 1484. Group Sold Products By The Date 1 2 3 4 5 6 7 # Write your MySQL query statement below select sell_date, COUNT(DISTINCT product) num_sold, group_concat(DISTINCT product) products from Activities group by sell_date order by sell_date Colored by Color Scripter cs 2022. 3. 30.
leetcode 1581. Customer Who Visited but Did Not Make Any Transactions 1 2 3 4 5 6 7 8 /* Write your PL/SQL query statement below */ select customer_id, count(visit_id) as count_no_trans from visits where visit_id not in ( select visit_id from transactions ) group by customer_id Colored by Color Scripter cs 2022. 3. 30.
leetcode 1795. Rearrange Products Table 1 2 3 4 5 6 7 8 9 /* Write your PL/SQL query statement below */ select * from( select product_id, 'store1' store, store1 price from products union select product_id, 'store2' store, store2 price from products union select product_id, 'store3' store, store3 price from products ) where price is not null; Colored by Color Scripter cs 2022. 3. 30.
leetcode 1587. Bank Account Summary II 1 2 3 4 5 6 7 /* Write your PL/SQL query statement below */ select u.name, sum(t.amount) as balance from users u join Transactions t on u.account=t.account group by u.name having sum(t.amount)>10000 cs 2022. 3. 30.
leetcode 1873. Calculate Special Bonus 1 2 3 4 5 /* Write your PL/SQL query statement below */ select employee_id ,case when mod(employee_id, 2)=1 and substr(name,1,1)!='M' then salary else 0 end as bonus from employees; Colored by Color Scripter cs 2022. 3. 29.
leetcode 1693. Daily Leads and Partners 1 2 3 4 5 6 7 8 /* Write your PL/SQL query statement below */ select to_char(date_id, 'yyyy-mm-dd') as date_id , make_name , count(distinct lead_id) as unique_leads , count(distinct partner_id) as unique_partners from DailySales group by date_id, make_name cs 2022. 3. 29.
leetcode 1741. Find Total Time Spent by Each Employee 1 2 3 4 5 /* Write your PL/SQL query statement below */ select TO_CHAR(event_day, 'YYYY-MM-DD') as day, emp_id, sum(out_time - in_time) as total_time from Employees group by event_day, emp_id order by 1, 2, 3 Colored by Color Scripter cs 2022. 3. 29.