2011-11-11 51 views

回答

5

你的問題是有點矛盾的,它最前一頁請求的平均數量每天的訂單,然後平均訂單要求(至極建議你想要的平均數量,而不是平均數訂單)

這應該給你的每一天您指定的範圍內averagy數量(插入你的表名雖然):

SELECT TRUNC(order_date) AS order_day, 
     AVG(qty) AS daily_orders 
    FROM <table> 
WHERE order_date 
      BETWEEN TO_DATE('31-OCT-2011 00:00:00', 'DD-MON-YYYY HH24:MI:SS') 
       AND TO_DATE('04-NOV-2011 23:59:59', 'DD-MON-YYYY HH24:MI:SS') 
GROUP BY TRUNC(order_date); 

如果你實際上是要求平均每天的訂單(不平均數量)在時間那麼你需要運行:

SELECT AVG(orders_per_day) 
    FROM (
     SELECT TRUNC(order_date), count(*) AS orders_per_day 
     FROM <table> 
     WHERE order_date 
       BETWEEN TO_DATE('31-OCT-2011 00:00:00', 'DD-MON-YYYY HH24:MI:SS') 
        AND TO_DATE('04-NOV-2011 23:59:59', 'DD-MON-YYYY HH24:MI:SS') 
     GROUP BY TRUNC(order_date) 
     ); 

希望它有幫助...

相關問題