abc三个表,怎么求销量啊,求大神帮我把销量最大的sql语句写出来,谢谢了

如题所述

一共三张表,表一用a,表二用b,表三用c,由于不知道销量是哪个字段,请自己写明:
select *
from a,b,c
where a.Custermer_ID=b.Custermer_ID
and b.CheckID=c.CheckID
and c.时间>='2016-03-01'
and c.时间<'2016-04-01'
order by 销量 desc
温馨提示:内容为网友见解,仅供参考
第1个回答  2016-03-17
先把表贴出来啊追问

我现在的目的就是求2015年3月的自营铺销售最大的货号

请求解决

追答

select checkgoodsId, max(xiaoliang) from (
select c.checkgoodsId as checkgoodId, sum(c.quantiy) as xiaoliang
from 表1 a, 表2 b, 表3 c
where a.customer_id = b.customer_id
and b.checkId = c.checkid
and a.method = "自营"
and b.checkDate between "2015-03-01" and "2015-03-31"
group by c.checkgoogsId
) group by checkgoodsId

主要是内层sql,外层的分组也可以,排序也可以

追问

下面怎么两个group by

本回答被提问者采纳
相似回答