如何在 SELECT 中找到一年的第一天?
How to find first day of year in SELECT?
SELECT `DATE`,`SomeValue1`,`SomeValue2`
FROM `SomeTableName`
WHERE (`DATE` >= [...first day of the year in date format...])
我找到了这个月 - 但我对一年的掌握还不够:(我正在寻找这个用于单独查询以查找月初和现在之间的数据)
I found this for month - but I don't QUITE have the grasp enough for year: (I was looking for this for a separate query to find data between beginning of month and now)
WHERE (`DATE` between DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW() )
我认为您需要:
WHERE (`DATE` between DATE_FORMAT(NOW() ,'%Y-01-01') AND NOW() )
老实说,你可以这样做:
To be honest, you could do:
WHERE (`DATE` between DATE_FORMAT(NOW() ,'%Y') AND NOW() )
这篇关于MySQL 选择年和月的第一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!