Last active
August 29, 2015 14:02
-
-
Save yuitest/122504043cbc3444054a to your computer and use it in GitHub Desktop.
アイコン集計
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
SELECT | |
it1.user_id | |
, it1.username | |
, it1.tweeted_at AS icon_from | |
, ( | |
SELECT | |
MIN(it2.tweeted_at) | |
FROM icon_tweet AS it2 | |
WHERE | |
it1.username = it2.username | |
AND it1.image_sha1 <> it2.image_sha1 | |
AND it1.tweeted_at < it2.tweeted_at | |
) AS icon_to | |
, it1.mime_type | |
, it1.image | |
, it1.image_sha1 | |
FROM icon_tweet AS it1 | |
GROUP BY | |
icon_to | |
ORDER BY | |
icon_from DESC | |
, icon_to DESC | |
, user_id ASC | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
icon_tweet は VIEW なので JOIN してあるものです。
元のテーブルの定義はしっかり正規化してあるのでご安心ください。