gpt4 book ai didi

mysql - 按日期加入查询

转载 作者:可可西里 更新时间:2023-11-01 09:02:25 25 4
gpt4 key购买 nike

请有人帮助我。

我需要加入这两个查询并按小时分组。查询结果可以有很多天。

结果:Query1

SELECT DATE_FORMAT( Venta.fechaImpresion,  "%h" ) AS fechaImpresion2, COUNT( * ) AS total
FROM `Venta`
WHERE Venta.fechaImpresion LIKE "2016-05-02 %"
GROUP BY HOUR( Venta.fechaImpresion ) , DAY( Venta.fechaImpresion )
LIMIT 0 , 30

结果:Query2

SELECT DATE_FORMAT(Venta.fechaImpresion,"%h") as fechaImpresion FROM `Venta`
where Venta.fechaImpresion >= "2016-05-02" and Venta.fechaImpresion <= "2016-05-09"
GROUP BY hour( Venta.fechaImpresion)

如果我尝试加入一个查询,结果为零。

SELECT DATE_FORMAT( Venta.fechaImpresion,  "%h" ) AS fecha, dia1.total AS total1
FROM `Venta`
LEFT JOIN (

SELECT DATE_FORMAT( Venta.fechaImpresion, "%h" ) AS fechaImpresion
FROM `Venta`
WHERE Venta.fechaImpresion >= "2016-05-02"
AND Venta.fechaImpresion <= "2016-05-09"
GROUP BY HOUR( Venta.fechaImpresion )
)fecha ON fecha.fechaImpresion = Venta.fechaImpresion
LEFT JOIN (

SELECT DATE_FORMAT( Venta.fechaImpresion, "%h" ) AS fechaImpresion2, COUNT( * ) AS total
FROM `Venta`
WHERE Venta.fechaImpresion LIKE "2016-05-02 %"
GROUP BY HOUR( Venta.fechaImpresion ) , DAY( Venta.fechaImpresion )
)dia1 ON ( dia1.fechaImpresion2 = fecha.fechaImpresion )
WHERE Venta.fechaImpresion >= "2016-05-02"
AND Venta.fechaImpresion <= "2016-05-09"
GROUP BY HOUR( Venta.fechaImpresion )

最佳答案

你可以这样试试

从第一个表中选择b.second表列,a.*,b第二个表中a.date列=b.date列

关于mysql - 按日期加入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37241984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com