dsyak22488 2015-09-13 22:26
浏览 19

如何在php中填写sql结果的缺失日期时间值

I have an sql request that returns record counts for every 5 minutes (or 15 minutes). So I can show that on a line graphic. But this data by itself returns wrong graphic, because some time spans have no records so no date returns for that intervals and this is causes to show a wrong graphic.

Here is my sql code.

SELECT
        YEAR(postdate) as Y, MONTH(postdate) as M, DAY(postdate) as D, HOUR(postdate) as H, MINUTE(postdate),
        FLOOR(MINUTE(postdate) / 5) * 5 AS MinIntVal,
        SUM(CASE type WHEN 'ins' THEN 1 ELSE 0 END) AS Instagram,
        SUM(CASE type WHEN 'twi' THEN 1 ELSE 0 END) AS Twitter,
        SUM(1) as TotalPost

FROM
entries
WHERE
    postdate IS NOT NULL
    AND postdate >= DATE_ADD(CURDATE(), INTERVAL -5 DAY)
GROUP BY
    YEAR(postdate), MONTH(postdate), DAY(postdate), MinIntVal
ORDER BY D DESC, H DESC, MinIntVal Desc

And result is below wrong graphic

But the desired / expected result should be looked like below enter image description here

So in php how can I add missing 'empty' date values or someone suggested I should add an other table only contains dates, but I have no idea how it should work.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效