22 lines
663 B
Plaintext
22 lines
663 B
Plaintext
|
|
# Demonstrate GROUP BY with aggregate functions in the SQL frontend.
|
||
|
|
|
||
|
|
fact Employee(alice, 30, engineering).
|
||
|
|
fact Employee(bob, 25, sales).
|
||
|
|
fact Employee(carol, 35, engineering).
|
||
|
|
fact Employee(dave, 28, marketing).
|
||
|
|
fact Employee(eve, 32, sales).
|
||
|
|
|
||
|
|
schema Employee(name, age, dept).
|
||
|
|
|
||
|
|
# Count all employees.
|
||
|
|
sql SELECT COUNT(*) FROM Employee;
|
||
|
|
|
||
|
|
# Count and average age per department.
|
||
|
|
sql SELECT dept, COUNT(*) AS headcount, AVG(age) AS avg_age FROM Employee GROUP BY dept;
|
||
|
|
|
||
|
|
# Min and max age per department.
|
||
|
|
sql SELECT dept, MIN(age), MAX(age) FROM Employee GROUP BY dept;
|
||
|
|
|
||
|
|
# Sum of ages in engineering.
|
||
|
|
sql SELECT SUM(age) FROM Employee WHERE dept = 'engineering';
|