Created
June 30, 2017 07:38
-
-
Save pochemuto/94f433b7677749ad1d19c068b6598ba6 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 null as id, | |
pic."user" as user_id, | |
118751606 as creator_id, | |
'Неоплаченные картинки' as name, | |
'картинки' as unit, | |
price, | |
count(*) as "count", | |
sysdate as TIME, | |
pic.category as category | |
from mbo11685 pic | |
LEFT JOIN mbo_user u on u.id = pic."user" | |
LEFT JOIN market_content.category cat on cat.hyper_id = pic.category | |
LEFT JOIN ( | |
SELECT category_id, price FROM ( | |
SELECT | |
category_id, | |
operation_id, | |
since, | |
price, | |
rank() | |
OVER ( | |
PARTITION BY category_id | |
ORDER BY since DESC ) rnk | |
FROM ng_category_operation_tarif s | |
WHERE s.operation_id = 2 | |
) price where rnk = 1 | |
) tarif on tarif.category_id = cat.guru_category_id | |
GROUP BY pic."user", pic.category, price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment