假设我有一个如下所示的表 Order:
: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 日:
-payment_option_id 为 1 的单位:4 个单位
-payment_option_id 为 2 的单位:0 个单位
7 月 8 日:
payment_option_id 为 1 的单位:12 单位 ...
获取这些数据的方法是什么?
谢谢