2013-07-09 73 views
1

說我有一個表的順序,看起來像這樣:集團由兩列和計算

:price 
:payment_option_id 
:created_at 

現在,我能夠獲得對已售出的所有單位(每行被視爲一個單位)每個payment_option_id,這樣做:

SELECT count(*) FROM Order WHERE payment_option_id = 3 
SELECT count(*) FROM Order WHERE payment_option_id = 4 
SELECT count(*) FROM Order WHERE payment_option_id = ... 

不過,現在我想獲得(如果它在一個查詢的可能)已經由每天售出的所有單位,這樣我就可以報告是這樣的:

7月7日的:
-units與payment_option_id 1:4臺
-units與payment_option_id 2:0單位

月8日:
單位與payment_option_id 1:12臺 ...

什麼是獲取這些數據的方法?

感謝

回答

0

,你可以通過如下的組用逗號分隔的項目:

SELECT count(*), created_at FROM Order GROUP BY payment_option_id, created_at 
+0

這是很酷,但我將如何從中日知道是每個返回的計數(*) –

+0

請找到編輯 – Varada

0

請嘗試:

select 
    Created_at, 
    payment_option_id, 
    COUNT(*) payment_option_id_num 
from 
    [Order] 
group by Created_at, payment_option_id