😃

MySQLで月の仮想表を作る

2021/04/06に公開約600字

sql

SELECT
    date_format(date_add('2020-03-01', interval td.generate_series month), '%Y-%m') as month,
    date_format(date_add('2020-03-01', interval td.generate_series month), '%Y-%m-%d') as start_of_month,
    date_format(date_add(date_add('2020-03-01', interval td.generate_series + 1 month), interval -1 day), '%Y-%m-%d') as end_of_month
FROM (
    SELECT 0 generate_series FROM DUAL WHERE (@num:=1-1)*0 UNION ALL
    SELECT @num:=@num+1 FROM `information_schema`.COLUMNS LIMIT 13
) as td

結果

Discussion

ログインするとコメントできます