如何编辑我的查询以显示每天的输出?

时间:2017-08-03 21:13:21

标签: php mysql sql

如何编辑以下查询以返回

,而不是返回5行
date --- rows found
date --- rows found
date --- rows found

这是查询

SElECT * FROM emails WHERE maildate >= DATE_ADD(CURDATE(), INTERVAL -3 DAY) and company_id = 1 order by maildate desc

1 个答案:

答案 0 :(得分:0)

maildateCOUNT(*)上的小组应该有效:

SELECT maildate, COUNT(*) as TotalEmails --change alias as desired
FROM emails
WHERE maildate >= DATE_ADD(CURDATE(), INTERVAL -3 DAY) 
AND company_id = 1 
GROUP BY date(maildate) --Remove timestamp for grouping
ORDER BY maildate desc

虽然目前还不清楚你想要归还什么。样本数据和预期输出会有所帮助。