Skip to content

Instantly share code, notes, and snippets.

@yuitest
Last active August 29, 2015 14:02
Show Gist options
  • Save yuitest/122504043cbc3444054a to your computer and use it in GitHub Desktop.
Save yuitest/122504043cbc3444054a to your computer and use it in GitHub Desktop.
アイコン集計
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
;
@yuitest
Copy link
Author

yuitest commented Jun 6, 2014

icon_tweet は VIEW なので JOIN してあるものです。
元のテーブルの定義はしっかり正規化してあるのでご安心ください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment