数据库:MySQL
表结构:
我的代码:
select month(xl.zTime) '月份',
(case when((select sum(cp.pricexl.SALE_AMOUNT)from 销量明细 xl
left join 客户明细 kh on xl.customId = kh.customId
left join 产品明细 cp on xl.pid = cp.pid
where kh.Country = 'China' and month(xl.zTime) = 08) > 10000) then '合格'
when ((select sum(cp.pricexl.SALE_AMOUNT)from 销量明细 xl
left join 客户明细 kh on xl.customId = kh.customId
left join 产品明细 cp on xl.pid = cp.pid
where kh.Country = 'China' and month(xl.zTime) = 09) > 12000)then '合格'
else '不合格' end)
as '中国业绩情况',
(case when((select sum(cp.pricexl.SALE_AMOUNT)from 销量明细 xl
left join 客户明细 kh on xl.customId = kh.customId
left join 产品明细 cp on xl.pid = cp.pid
where kh.Country = 'England' and month(xl.zTime) = 08) > 10000)then '合格'
when((select sum(cp.pricexl.SALE_AMOUNT)from 销量明细 xl
left join 客户明细 kh on xl.customId = kh.customId
left join 产品明细 cp on xl.pid = cp.pid
where kh.Country = 'England' and month(xl.zTime) = 09) > 12000)then '合格'
else '不合格' end)
as '英国业绩情况'
from 销量明细 xl
left join 客户明细 kh on xl.customId = kh.customId
left join 产品明细 cp on xl.pid = cp.pid
group by month(xl.zTime)
输出结果: