├── Article Views I.sql ├── Average_Selling_Price.sql ├── Average_Time_of_Process.sql ├── Biggest Single Number.sql ├── Classes More Than 5 Students.sql ├── Confirmation Rate.sql ├── Consecutive Numbers.sql ├── Count Salary Categories.sql ├── Employee Bonus.sql ├── Game_Play_Analysis_IV.sql ├── README.md ├── Triangle Judgement.sql ├── Write your MySQL query statement below.sql ├── asked_step_by_step.sql ├── id - Copy - Copy (2) - Copy - Copy.sql ├── id - Copy - Copy (2) - Copy.sql ├── id - Copy - Copy (2).sql ├── id - Copy - Copy - Copy - Copy - Copy.sql ├── id - Copy - Copy - Copy - Copy.sql ├── id - Copy - Copy - Copy.sql └── two.sql /Article Views I.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | 3 | select distinct author_id as id from Views 4 | where author_id = viewer_id 5 | order by id; -------------------------------------------------------------------------------- /Average_Selling_Price.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | WITH CTE AS ( 3 | SELECT p.product_id, 4 | CASE WHEN purchase_date >= start_date 5 | AND purchase_date <= end_date 6 | THEN units * price 7 | END total_price, 8 | units 9 | from Prices as p 10 | LEFT join UnitsSold as u 11 | on p.product_id = u.product_id 12 | HAVING total_price IS NOT NULL 13 | ) 14 | SELECT p.product_id, 15 | ROUND(ifnull(sum(total_price)/sum(units), 0),2) as average_price 16 | from Prices as p 17 | LEFT JOIN CTE ON p.product_id = CTE.product_id 18 | group by 1; -------------------------------------------------------------------------------- /Average_Time_of_Process.sql: -------------------------------------------------------------------------------- 1 | select a1.machine_id, round(avg(a2.timestamp-a1.timestamp), 3) as processing_time 2 | from Activity a1 3 | join Activity a2 4 | on a1.machine_id=a2.machine_id and a1.process_id=a2.process_id 5 | and a1.activity_type='start' and a2.activity_type='end' 6 | group by a1.machine_id -------------------------------------------------------------------------------- /Biggest Single Number.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT MAX(num) AS num 3 | FROM ( 4 | SELECT num 5 | FROM MyNumbers 6 | GROUP BY num HAVING COUNT(num) = 1 7 | ORDER BY num DESC 8 | ) AS single_numbers -------------------------------------------------------------------------------- /Classes More Than 5 Students.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT class 3 | FROM courses 4 | GROUP BY class 5 | HAVING COUNT(student) >= 5; 6 | -------------------------------------------------------------------------------- /Confirmation Rate.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | select s.user_id, round(avg(if(c.action="confirmed",1,0)),2) as confirmation_rate 3 | from Signups as s left join Confirmations as c on s.user_id= c.user_id group by user_id; 4 | 5 | -------------------------------------------------------------------------------- /Consecutive Numbers.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | with cte as ( 3 | select num, 4 | lead(num,1) over() num1, 5 | lead(num,2) over() num2 6 | from logs 7 | 8 | ) 9 | 10 | select distinct num ConsecutiveNums from cte where (num=num1) and (num=num2) -------------------------------------------------------------------------------- /Count Salary Categories.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT "Low Salary" AS category, 3 | sum(income < 20000) AS accounts_count 4 | FROM Accounts 5 | 6 | UNION 7 | 8 | SELECT "Average Salary" AS category, 9 | sum(income BETWEEN 20000 AND 50000) AS accounts_count 10 | FROM Accounts 11 | 12 | UNION 13 | 14 | SELECT "High Salary" AS category, 15 | sum(income > 50000) AS accounts_count 16 | FROM Accounts; -------------------------------------------------------------------------------- /Employee Bonus.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name, bonus 3 | FROM Employee 4 | LEFT JOIN Bonus ON Employee.empId=Bonus.empId 5 | WHERE Bonus.bonus < 1000 OR Bonus.bonus IS NULL; -------------------------------------------------------------------------------- /Game_Play_Analysis_IV.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | WITH playersMinEventDate(player_id, event_date) 3 | 4 | AS ( 5 | SELECT player_id, MIN(event_date) 6 | FROM Activity 7 | GROUP BY player_id 8 | ), 9 | 10 | activePlayersCount (players_count) 11 | 12 | AS ( 13 | SELECT COUNT(_activity.player_id) 14 | FROM Activity _activity 15 | LEFT JOIN playersMinEventDate _min_event_date ON _activity.player_id = _min_event_date.player_id 16 | WHERE DATE_ADD(_min_event_date.event_date, INTERVAL 1 DAY) = _activity.event_date 17 | ) 18 | 19 | SELECT ROUND(players_count / COUNT(DISTINCT _activity.player_id), 2) AS fraction 20 | FROM Activity _activity, activePlayersCount -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SQL-QUESTION -------------------------------------------------------------------------------- /Triangle Judgement.sql: -------------------------------------------------------------------------------- 1 | Write your MySQL query statement below 2 | select x, y, z, 3 | case when x + y > z and x + z > y and y + z > x then 'Yes' 4 | else 'No' 5 | end as triangle 6 | from Triangle -------------------------------------------------------------------------------- /Write your MySQL query statement below.sql: -------------------------------------------------------------------------------- 1 | select name,population,area 2 | from World 3 | where area >= 3000000 or population >=25000000 4 | -------------------------------------------------------------------------------- /asked_step_by_step.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT activity_date AS day, COUNT(DISTINCT user_id) AS active_users 3 | FROM Activity 4 | WHERE (activity_date > "2019-06-27" AND activity_date <= "2019-07-27") 5 | GROUP BY activity_date; -------------------------------------------------------------------------------- /id - Copy - Copy (2) - Copy - Copy.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT NAME FROM CUSTOMER WHERE REFEREE_ID IS NULL OR REFEREE_ID!=2; -------------------------------------------------------------------------------- /id - Copy - Copy (2) - Copy.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT NAME FROM CUSTOMER WHERE REFEREE_ID IS NULL OR REFEREE_ID!=2; -------------------------------------------------------------------------------- /id - Copy - Copy (2).sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT NAME FROM CUSTOMER WHERE REFEREE_ID IS NULL OR REFEREE_ID!=2; -------------------------------------------------------------------------------- /id - Copy - Copy - Copy - Copy - Copy.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT NAME FROM CUSTOMER WHERE REFEREE_ID IS NULL OR REFEREE_ID!=2; -------------------------------------------------------------------------------- /id - Copy - Copy - Copy - Copy.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT NAME FROM CUSTOMER WHERE REFEREE_ID IS NULL OR REFEREE_ID!=2; -------------------------------------------------------------------------------- /id - Copy - Copy - Copy.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT NAME FROM CUSTOMER WHERE REFEREE_ID IS NULL OR REFEREE_ID!=2; -------------------------------------------------------------------------------- /two.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | select tweet_id 3 | from Tweets 4 | where CHAR_LENGTH(content) > 15 --------------------------------------------------------------------------------