Skip to content

Instantly share code, notes, and snippets.

@sqlparser
Created December 12, 2023 08:18
Show Gist options
  • Save sqlparser/2442c922275a625895e20bab27d68fc2 to your computer and use it in GitHub Desktop.
Save sqlparser/2442c922275a625895e20bab27d68fc2 to your computer and use it in GitHub Desktop.
IBM Netezza Sample SQL
```sql
-- netezza sample sql
INSERT INTO films SELECT * FROM tmp;
INSERT INTO emp_copy WITH employee AS (select * from
emp) SELECT * FROM employee;
UPDATE emp_copy SET grp = 'gone' WHERE id =
(WITH employee AS (select * from emp) SELECT id FROM employee WHERE id
= 1);
DELETE FROM emp_copy WHERE id IN
(WITH employee AS (SELECT * FROM emp_copy where grp = 'gone')
SELECT id FROM employee);
WITH manager (mgr_id, mgr_name, mgr_dept) AS
(SELECT id, name, grp
FROM emp_copy
WHERE mgr = id AND grp != 'gone'),
employee (emp_id, emp_name, emp_mgr) AS
(SELECT id, name, mgr_id
FROM emp_copy JOIN manager ON grp = mgr_dept),
mgr_cnt (mgr_id, mgr_reports) AS
(SELECT mgr, COUNT (*)
FROM emp_copy
WHERE mgr != id
GROUP BY mgr)
SELECT *
FROM employee JOIN manager ON emp_mgr = mgr_id
JOIN mgr_cnt ON emp_mgr = mgr_id
WHERE emp_id != mgr_id
ORDER BY mgr_dept;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment