LoginSignup
1
0

More than 3 years have passed since last update.

SQL GROUP_BY ORDER_BY DATE_FORMATで日付を比較

Posted at
記事数デイリー推移
select genre, DATE_FORMAT(`published_at`, '%Y-%m-%d') as date, count(id) from news where published_at>="2017-09-01 00:00:00" and status=10 GROUP BY date, genre ORDER BY genre, date
記事数マンスリー推移
select genre, DATE_FORMAT(`published_at`, '%Y-%m') as month, count(id) from news where published_at>="2015-01-01 00:00:00" and status=10 GROUP BY month, genre ORDER BY genre, month desc

解説

[DATE_FORMAT]
format 文字列に従って、date 値を書式設定します。
次の指定子が format 文字列で使用されている場合があります。書式指定子文字の前には、「%」 文字を付ける必要があります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0