Skip to content

Commit f3dbfbc

Browse files
committed
Section 05 : Advanced Select and Joins - part 01
1 parent 2e0351e commit f3dbfbc

7 files changed

+22
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT a.employee_id, a.name, COUNT(*) AS reports_count, ROUND(AVG(b.age)) AS average_age
2+
FROM Employees a, Employees b
3+
WHERE a.employee_id = b.reports_to
4+
GROUP BY 1
5+
ORDER BY 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SELECT DISTINCT employee_id, department_id
2+
FROM Employee
3+
WHERE employee_id IN
4+
(
5+
SELECT employee_id
6+
FROM Employee
7+
GROUP BY 1
8+
HAVING COUNT(*) = 1
9+
)
10+
OR primary_flag = 'Y'
11+
ORDER BY 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT x, y, z,
2+
CASE WHEN (x + y <= z OR y + z <= x OR x + z <= y) THEN 'No' ELSE 'Yes' END AS triangle
3+
FROM Triangle;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT DISTINCT l1.Num AS ConsecutiveNums
2+
FROM Logs l1, Logs l2, Logs l3
3+
WHERE l1.Id = l2.Id - 1 AND l2.Id = l3.Id - 1 AND l1.Num = l2.Num AND l2.Num = l3.Num

0 commit comments

Comments
 (0)