-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d370aef
commit 9d69faf
Showing
4 changed files
with
33 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
-- @conn postgres | ||
|
||
-- @block Create a table | ||
CREATE TABLE employees ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(100), | ||
department VARCHAR(100), | ||
salary INTEGER | ||
); | ||
-- @conn xtdb | ||
|
||
-- 👇 Click here 👇 | ||
-- @block Insert sample data | ||
INSERT INTO employees (name, department, salary) VALUES | ||
('John Doe', 'IT', 75000), | ||
('Jane Smith', 'HR', 65000), | ||
('Bob Johnson', 'Finance', 80000), | ||
('Alice Brown', 'Marketing', 70000), | ||
('Charlie Davis', 'IT', 85000); | ||
|
||
-- @block | ||
DROP TABLE employees | ||
INSERT INTO employees (_id, name, department, salary) VALUES | ||
(1, 'John Doe', 'IT', 75000), | ||
(2, 'Jane Smith', 'HR', 65000), | ||
(3, 'Bob Johnson', 'Finance', 80000), | ||
(4, 'Alice Brown', 'Marketing', 70000), | ||
(5, 'Charlie Davis', 'IT', 85000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,35 @@ | ||
-- @conn postgres | ||
-- @conn xtdb | ||
|
||
-- @block | ||
-- Exercise 1: Basic SELECT | ||
-- Retrieve all employees from the IT department | ||
SELECT * FROM employees WHERE department = 'IT'; | ||
|
||
-- @block | ||
SELECT * FROM employees; | ||
|
||
-- Exercise 2: Aggregation | ||
-- Calculate the average salary for each department | ||
-- @block | ||
SELECT department, AVG(salary) as avg_salary | ||
FROM employees | ||
GROUP BY department; | ||
|
||
-- @block | ||
-- Exercise 3: Joins (assuming we add another table) | ||
-- Create a departments table | ||
CREATE TABLE departments ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(100), | ||
budget INTEGER | ||
); | ||
|
||
INSERT INTO departments (name, budget) VALUES | ||
('IT', 500000), | ||
('HR', 300000), | ||
('Finance', 700000), | ||
('Marketing', 400000); | ||
|
||
-- @block | ||
INSERT INTO departments (_id, name, budget) VALUES | ||
(1, 'IT', 500000), | ||
(2, 'HR', 300000), | ||
(3, 'Finance', 700000), | ||
(4, 'Marketing', 400000); | ||
|
||
-- Join employees with departments to get department budgets | ||
-- @block | ||
SELECT e.name, e.department, d.budget | ||
FROM employees e | ||
JOIN departments d ON e.department = d.name; | ||
|
||
-- @block | ||
-- Exercise 4: Subqueries | ||
-- Find employees who earn more than the average salary | ||
-- @block | ||
SELECT name, salary | ||
FROM employees | ||
WHERE salary > (SELECT AVG(salary) FROM employees); |