-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL BI-WEEKLY ASSESSMENT Solution Blessing Adeyemi.txt
43 lines (37 loc) · 1.32 KB
/
SQL BI-WEEKLY ASSESSMENT Solution Blessing Adeyemi.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Write your MySQL query statement below:
SELECT E1.name AS Employee
FROM Employee AS E1
INNER JOIN Employee AS E2 ON E1.Managerid = E2.id
WHERE E1.salary > E2.salary;
2.# Write your MySQL query statement below
DELETE p1 FROM Person AS p1,
Person AS p2
WHERE p1.id > p2.id
AND p1.email = p2.email;
3. # Write your MySQL query statement below
SELECT Customers.name AS Customers
FROM Customers
LEFT JOIN Orders
ON Customers.id = orders.customerId
WHERE orders.customerId IS NULL;
4. Write your MySQL query statement below
UPDATE Salary
SET Sex = CASE Sex WHEN 'm' THEN 'f' ELSE 'm'
END;
5. # Write your MySQL query statement below
SELECT activity_date as day, COUNT(DISTINCT user_id) as active_users
FROM Activity
WHERE datediff('2019-07-27',activity_date)<30
AND activity_date <= '2019-07-27'
GROUP BY activity_date;
6. # Write your MySQL query statement below
Select sell_date, count(distinct product) as num_sold, group_concat(distinct product) as products
From Activities
Group by sell_date
Order by sell_date;
7. # Write your MySQL query statement below
SELECT P1.product_id, P1.product_name
FROM Product P1, Sales S1
WHERE P1.product_id = S1.product_id
GROUP BY (P1.product_id)
HAVING MIN(sale_date) >= CAST("2019-01-01" AS DATE) and MAX(sale_date) <= CAST("2019-03-31" AS DATE);