Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql中select查询的逐日搜索_Mysql - Fatal编程技术网

mysql中select查询的逐日搜索

mysql中select查询的逐日搜索,mysql,Mysql,我在mysql的表中有一个日期字段。我希望以这样的方式获取记录,即从今天到上一年,它以以下方式提供记录 id-->日-->计数器 这意味着我需要每天的智慧计数器。在过去一年中,每天(星期日、星期一等)插入多少条记录 plz帮助 多谢各位 DAY函数可以替换为DATE以获取完整日期,to_DAYS以获取0年的天数,WEEKDAY以获取周一到周日,等等 编辑:要按工作日显示,请使用DAYNAME函数(DAYNAME(dateField)) 在where子句中使用上一个年份,并在每个年份中按dayn

我在mysql的表中有一个日期字段。我希望以这样的方式获取记录,即从今天到上一年,它以以下方式提供记录

id-->日-->计数器

这意味着我需要每天的智慧计数器。在过去一年中,每天(星期日、星期一等)插入多少条记录

plz帮助 多谢各位

DAY函数可以替换为DATE以获取完整日期,to_DAYS以获取0年的天数,WEEKDAY以获取周一到周日,等等

编辑:要按工作日显示,请使用DAYNAME函数(DAYNAME(dateField))


在where子句中使用上一个
年份
,并在每个
年份
中按
dayname
分组计算出现次数。您可以在
工作日
数字上订购结果

示例

select   year( date ) as year
       , dayname( date ) as day
       , count( date ) as counter
  from table_name
 where 
       date between ( curdate() - interval 1 year ) and curdate()
       -- or the following, to match all from prev year
       -- year( date ) >= year( curdate() - interval 1 year )
 group by 1, 2 -- year and dayname
 order by year 
          , field( weekday( date ), 6, 0, 1, 2 ,3 ,4, 5 ) -- sun to sat

这听起来并不难。你们试过什么了?很好,杰夫……但若我想在周日周一的时候展示结果,那个我该怎么办。。。
select   year( date ) as year
       , dayname( date ) as day
       , count( date ) as counter
  from table_name
 where 
       date between ( curdate() - interval 1 year ) and curdate()
       -- or the following, to match all from prev year
       -- year( date ) >= year( curdate() - interval 1 year )
 group by 1, 2 -- year and dayname
 order by year 
          , field( weekday( date ), 6, 0, 1, 2 ,3 ,4, 5 ) -- sun to sat