Skip to content

Commit aafef7b

Browse files
new sql training, unit 0x04
1 parent 38bf4ef commit aafef7b

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎docs/databases_sql_training.pdf‎

993 KB
Binary file not shown.

‎exercises/db_training_0x04.sql‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- (C) 2025 A.Voß, a.voss@fh-aachen.de, info@codebasedlearning.dev
1+
-- (C) A.Voß, a.voss@fh-aachen.de, info@codebasedlearning.dev
22

33
-- SQL-Commands Unit 0x04
44

@@ -57,10 +57,15 @@ WHERE E.salary = Stats.min;
5757
SELECT E.name, E.salary FROM hr_employee E
5858
WHERE E.salary IN (5000,12000,18000);
5959

60+
SELECT employee_id, min(salary) FROM hr_employee
61+
GROUP BY employee_id;
62+
63+
SELECT min(salary) FROM hr_employee X
64+
WHERE X.employee_id = 5;
65+
6066
-- group-functions with IN
6167
-- Caution, typical mistake: this is NOT "the employees with the lowest salary in
62-
-- their team". IN compares with the minimum of ANY team, e.g. Leon (70000, team Ben)
63-
-- is listed because 70000 is the minimum of team Emma.
68+
-- their team". Here IN compares with the minimum of ANY team.
6469
SELECT E.name, E.salary, E.employee_id FROM hr_employee E
6570
WHERE E.salary IN (
6671
SELECT min(salary) FROM hr_employee
@@ -75,7 +80,6 @@ WHERE E.salary = (
7580
);
7681

7782
-- ANY
78-
7983
-- all products from category 4 (milk products)
8084
SELECT name, price FROM shop_product WHERE category_id=4;
8185

‎exercises/proposed_solutions/db_solution_0x04.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- (C) 2025 A.Voß, a.voss@fh-aachen.de, info@codebasedlearning.dev
1+
-- (C) A.Voß, a.voss@fh-aachen.de, info@codebasedlearning.dev
22

33
-- SQL-Solutions Unit 0x04
44

0 commit comments

Comments
 (0)