简体   繁体   中英

How to get data of every first day of month for all month in my sql?

I have a table samples. It has data of every day of every month

  date         m1   m2   m3
'2017-01-01'   10   11    12
'2017-01-02'   10   10    12
'2017-01-03'   10   11    12
'2017-01-04'   10   8     12
'2017-02-01'   10   6     12
'2017-02-02'   10   14    12

I want the data like this

 date         m1   m2   m3
'2017-01-01'   10   11   12
'2017-02-01'   10   6    12
SELECT * from `Table` WHERE date_format(date,"%d") = '01'

You can use following querys

select * from your_table_name
where `date`= DATE_FORMAT(`date` ,'2017-%m-01')

or

select * from your_table_name
where DAY(`date`)= '01' and YEAR(`date`)='2017'

Note that this will return records of every first day of months for the year 2017

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM