Created
December 12, 2023 08:03
-
-
Save sqlparser/fc5b2d26d10a45f3af87941826cb97e9 to your computer and use it in GitHub Desktop.
Greenplum Sample SQL
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
```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) | |
) | |
SELECT region, | |
product, | |
SUM(quantity) AS product_units, | |
SUM(amount) AS product_sales | |
FROM orders | |
WHERE region IN (SELECT region FROM top_regions) | |
GROUP BY region, product; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment