我有一个每月销售的产品,我有用户的电子邮件
我希望看到每封电子邮件每月购买的总金额。
此外,所有月份的每封电子邮件的总金额合计
答案 0 :(得分:1)
尝试这样:
我理解这样的问题
select email,sum(amount),'2' as ord from (
select email,sum(amount) as amount ,month(d1) from t1 group by
month(d1),email) as t group by email
union all
select email,sum(amount) as amount,
'1' as ord from t1 group by month(d1),email
order by ord
此查询首先显示每月金额的总和,并在显示每封电子邮件的金额总和之后发送电子邮件