Created
April 8, 2019 14:25
-
-
Save urusai88/d5a3d3802bbe44670751cf5c2c414fd7 to your computer and use it in GitHub Desktop.
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
SELECT | |
id AS client_id, | |
(SELECT COUNT(*) FROM orders o1 WHERE o1.client_id = c.id AND o1.price < 1000) AS count1, | |
(SELECT COUNT(*) FROM orders o2 WHERE o2.client_id = c.id AND o2.price > 1000) AS count2 | |
FROM clients c | |
SELECT c.* FROM ( | |
SELECT *, | |
row_number() OVER (PARTITION BY client_id) AS num | |
FROM orders | |
) as c WHERE c.num % 3 = 0 | |
SELECT c.* FROM ( | |
SELECT *, | |
row_number() OVER (PARTITION BY client_id) AS num | |
FROM orders | |
WHERE price > 1000 | |
) as c WHERE c.num % 3 = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment