gpt4 book ai didi

sql - 每天计算和求和多个没有连接的表

转载 作者:行者123 更新时间:2023-12-02 04:55:43 27 4
gpt4 key购买 nike

我想计算订单发票的交付数量,并对每天交付的订单发票数量求和。像这样:

date  nb orders  orders$     nb delivery   
day1 5 1234,56 3
day2 6 665,88 7
..

我第一次尝试这个,一天可以,但一周不行,例如:

SELECT  
(SELECT COUNT(OPP.OPPNUM_0) FROM OPPOR OPP WHERE OPP.CREDAT_0=%1%),
(SELECT SUM(OPP.OPPAMT_0) FROM OPPOR OPP WHERE OPP.CREDAT_0=%1%),
(SELECT COUNT(SQH.SQHNUM_0) FROM SQUOTE SQH WHERE SQH.CREDAT_0=%1%),
(SELECT SUM(SQH.YCUMHTSEL_0) FROM SQUOTE SQH WHERE SQH.CREDAT_0=%1%),
(SELECT COUNT(SOH.SOHNUM_0) FROM SORDER SOH WHERE SOH.CREDAT_0=%1%),
(SELECT SUM(SOH.ORDNOT_0) FROM SORDER SOH WHERE SOH.CREDAT_0=%1%)
FROM dual

最佳答案

MySQL 提供了内置的按天过滤的查询:

SELECT COUNT(*) FROM table_name WHERE anydatefiled >= NOW() - INTERVAL 1 DAY

关于sql - 每天计算和求和多个没有连接的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22500892/

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