简体   繁体   English

如何在我的sql中获取月份中每个月的第一天的数据?

[英]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 请注意,这将返回2017年的每个月的第一天记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在mysql中获得每个对应月份的第一天? - How to get first day of every corresponding month in mysql? 如何从SQL中的给定月份和年份中获取月份的第一天和最后一天 - How to get the First day and last day of the month from given month and year in sql 如何获得一个月中每天的价值 - How to get values for every day in a month SQL查询,用于获取一个月中的每个第一个事件(按日期时间字段) - SQL query for fetching every first event (by datetime field) in day of a month 如何在 sql 的查询之间添加一个月的第一天和最后一天? - How to add first day and last day of month in between query in sql? 有没有办法获得上个月的第一天和当月的最后一天? - Is there a way to get the First day of the previous month and Last day of current month? 在 MariaDb 查询中,给定年份、月份和星期,如何获取一周中的第一天的星期几? - How to get the day of month, of the first day of a week, given the year the month and the week in a MariaDb query? 如何获取一年中每个月的销售数据 - How to get Sale data of every month of a year 如何检索日期从一个月的第一天开始的所有行 - How to retrieve all the rows with date starting the first day of a month 将sql中的字段更新为下个月的第一天 - Update field in sql to first day of the next month
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM