Last active
February 22, 2017 17:37
-
-
Save ByoungInKim/814e11b09b05e6340f3e11cd20cdd780 to your computer and use it in GitHub Desktop.
deduplicate data and then select recent data
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
-- deduplicate with recent data | |
SELECT * FROM | |
( | |
SELECT ROW_NUMBER() OVER(PARTITION BY date_key,CountryName ORDER BY regdatetime DESC) AS ROWNUM, * | |
FROM temp where packageName = 'com.test' | |
) A | |
WHERE ROWNUM = 1 AND date_key > '2017-01-10' order by date_key asc | |
-- example | |
/* | |
data | |
|user_id|data|reg_datetime| | |
| 1 | 2 |2016-10-21 | | |
| 1 | 5 |2016-10-22 | | |
| 1 | 23 |2016-10-23 | | |
after qurey | |
|user_id|data|reg_datetime| | |
| 1 | 23 |2016-10-23 | | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment