假设我有一个表格看起来像这样:
: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日:获取此数据的方法是什么?
由于
答案 0 :(得分:0)
您可以在组中使用逗号分隔的项目,如下所示:
SELECT count(*), created_at FROM Order GROUP BY payment_option_id, created_at
答案 1 :(得分:0)
请尝试:
select
Created_at,
payment_option_id,
COUNT(*) payment_option_id_num
from
[Order]
group by Created_at, payment_option_id