每天计算和总计多个没有连接的表

时间:2014-03-19 09:10:30

标签: sql

我想要计算订单发票的数量,并计算每天发货的订单发票金额。 像这样:

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

1 个答案:

答案 0 :(得分:0)

MySQL提供内置查询,按日过滤:

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