所选日期(周一,周二,周三等)的数据

时间:2017-06-30 07:27:18

标签: php mysql date

我有一个MySQL数据库,并在我们公司的本地网络应用程序中使用PHP。我正在尝试制作一个几乎完成的小型统计页面。但我想添加另一个字段,显示星期一到星期日这几天输入的数据量。

我尝试了很多,但都没有。

字段:IDcall_time

例如:

1

SELECT count(*) from tbl_event WHERE w(call_time) = 0

2

$TestDay = '2017-01-01'; //For Sunday
SELECT count(*) from tbl_event where call_time = ".$TestDay." 
or (DAYNAME(call_time) = DAYNAME(".$TestDay."))

3 个答案:

答案 0 :(得分:0)

如果我理解你的问题:

SELECT COUNT(*), DAYOFWEEK(call_time) AS dayname
FROM tbl_event
WHERE call_time > '2017-01-01'
GROUP BY DAYOFWEEK(call_time)

这将创建一个5或7天的列表以及表格中的出现次数。 (仅限于当年,2017年)

您可以添加一行AND DAYOFWEEK(call_time) = 5来限制某一天

答案 1 :(得分:0)

这将按一系列日期之间的正确顺序提供每周每日事件的摘要计数:

SELECT 
    dayname(`call_time`) as `Day Of Week`,
    dayofweek(`call_time`) as `DayOrder`,
    count(*) as `num_events`
FROM `tbl_event`
WHERE `call_time` BETWEEN '2017-01-01' AND '2017-01-30'
group by dayname(`call_time`)
order by dayofweek(`call_time`)

答案 2 :(得分:0)

@Ivo P. 谢谢你的答案,它与小触摸(

for ($varDay = 1; $varDay <= 7; $varDay++) {
    $Test = "SELECT COUNT(*), DAYOFWEEK(call_time) AS dayname FROM tbl_event WHERE DAYOFWEEK(call_time) = ".$varDay." GROUP BY DAYOFWEEK(call_time)";
}