如何在同一天内获取数据?

时间:2017-12-20 08:50:34

标签: mysql sql

我正在进行查询以在同一天内计算已验证的订单。关于如何计算,我可以做但是为了限制时间,你能帮助我吗?

例如:TIMESTAMPDIFF(HOUR, enddate, startdate) <= '24', 时间将在1天内,但可以是从一天到第二天。 那么如何在同一天内获取数据呢? 我的原始查询是:

SELECT COUNT(*),
1.0 * count(CASE WHEN TIMESTAMPDIFF(HOUR, `Created Datetime`, `Order Verification Date`) <= '2' THEN `BOB Sales Order Item` ELSE NULL END) / COUNT(`BOB Sales Order Item`) AS within_2hours_rate,
1.0 * count(CASE WHEN TIMESTAMPDIFF(DAY, `Created Datetime`, `Order Verification Date`) <= '24' THEN `BOB Sales Order Item` ELSE NULL END) / COUNT(`BOB Sales Order Item`) AS within_the_sameday_rate
FROM data.oms
WHERE `Created Datetime` BETWEEN '2017-10-29 00:00:00' AND '2017-11-04 23:59:59' AND `Order Verification Status` = 'finance_verified'

提前致谢!

1 个答案:

答案 0 :(得分:-1)

如果您要检查两次是否在同一个日历日,那么您可以DATE(`Created Datetime`) = DATE(`Order Verification Date`)