This file contains hidden or 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
```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 |
This file contains hidden or 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
```sql | |
-- mysql sample sql | |
SELECT | |
salesperson.name, | |
-- find maximum sale size for this salesperson | |
(SELECT MAX(amount) AS amount | |
FROM all_sales | |
WHERE all_sales.salesperson_id = salesperson.id) | |
AS amount, |
This file contains hidden or 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
```sql | |
-- Informix sample sql | |
CREATE VIEW myview (cola, colb) AS | |
SELECT colx, coly from firsttab | |
UNION | |
SELECT colx, colz from secondtab; | |
CREATE VIEW palo_alto AS | |
SELECT * FROM customer WHERE city = 'Palo Alto' | |
WITH CHECK OPTION |
This file contains hidden or 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
```sql | |
insert into t2 select * from t1; | |
insert into t2 select c1, c2 from t1; | |
CREATE VIEW v5 AS SELECT c1, CAST(c3 AS STRING) c3, CONCAT(c4,c5) c5, TRIM(c6) c6, "Constant" c8 FROM t1; | |
CREATE VIEW v7 (c1 COMMENT 'Comment for c1', c2) COMMENT 'Comment for v7' AS SELECT t1.c1, t1.c2 FROM t1; | |
``` |
This file contains hidden or 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
```sql | |
SELECT pageid, adid | |
FROM pageAds LATERAL VIEW explode(adid_list) adTable AS adid; | |
CREATE DATABASE merge_data; | |
CREATE TABLE merge_data.transactions( | |
ID int, | |
TranValue string, | |
last_update_user string) |
This file contains hidden or 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
```sql | |
MERGE INTO "my_schema".t1 USING "my_schema".t2 ON "my_schema".t1.a = "my_schema".t2.a | |
WHEN MATCHED THEN UPDATE SET "my_schema".t1.b = "my_schema".t2.b | |
WHEN NOT MATCHED THEN INSERT VALUES("my_schema".t2.a, "my_schema".t2.b); | |
MERGE INTO T1 USING T2 ON T1.A = T2.A | |
WHEN MATCHED AND T1.A > 1 THEN UPDATE SET B = T2.B | |
WHEN NOT MATCHED AND T2.A > 3 THEN INSERT VALUES (T2.A, T2.B); | |
``` |
This file contains hidden or 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
```sql | |
WITH regional_sales AS ( | |
SELECT region, SUM(amount) AS total_sales | |
FROM orders | |
GROUP BY region | |
), top_regions AS ( | |
SELECT region | |
FROM regional_sales | |
WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales) | |
) |
This file contains hidden or 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
```sql | |
SELECT PART, SUPPLIER, PRODNUM, PRODUCT | |
FROM (SELECT PART, PROD# AS PRODNUM, SUPPLIER | |
FROM PARTS | |
WHERE PROD# < 200) AS PARTX | |
LEFT OUTER JOIN PRODUCTS | |
ON PRODNUM = PROD#; | |
``` |
This file contains hidden or 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
```sql | |
CREATE OR REPLACE VIEW experienced_employee | |
(id COMMENT 'Unique identification number', Name) | |
COMMENT 'View for experienced employees' | |
AS SELECT id, name | |
FROM all_employee | |
WHERE working_years > 5; | |
``` |
This file contains hidden or 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
```sql | |
SELECT name, (SELECT raw avg(s.ratings.Overall) | |
FROM t.reviews as s)[0] AS overall_avg_rating | |
FROM hotel AS t | |
ORDER BY overall_avg_rating DESC | |
LIMIT 3; | |
``` |