感觉这个题目最难的地方在与不知道如何计数吧。
我写了下边这个代码,得出了题目要求的数据:
-------------------------------------------------------------------------------
自学习题4:图表.cpt
SELECT
strftime('%Y',c1.订购日期) as 年份,
strftime('%Y-%m',c1.订购日期) as 年月,
count(c1.订单ID) AS 订单数量,
sum(case when c1.是否已付='true' then 1 else 0 end) AS 是否已付,
sum(c2.单价*c2.数量*(1-折扣)) as 销售金额
FROM 订单 as c1 inner join 订单明细 as c2 ON c1.订单ID=c2.订单ID
group by 年月
--------------------------------------------------------------------------------