1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLで月末・月初

Posted at

SQLで月末のデータをとりたい

背景

dailyごとのMAUとかをサマったテーブルからその月の最終データだけ抜きたい

困りどころ

SQLで最終日ってどうとるっけ?毎月31日じゃねぇしな

SQLで月末日を取得する

LAST_DAY関数

引数に渡した日付の年月の月末日を返す

SELECT * FROM xxxx_data WHERE date_format(create_time, "%Y%m%d") = LAST_DAY(create_time, "%Y%m%d")

備考

LAST_DAY( )があるからといってFIRST_DAY( )はないので、"%Y%m%1"とかでフォーマットしてください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?