把排序后的sql作为一个子查询和其他表连接 如: select * from t1,(select 商品id ,sum(商品数量) total from table group by 商品id order by total desc )t2 where t1.col=t2.col
select 商品id ,b.name as 商品名, --次数可以连接查询相应商品信息,注意在group中体现。 sum(商品数量) as total from tablea a left join tableb b on a.商品id = b.id group by a.商品id,b.name order by total desc
select 商品id ,b.name as 商品名, --次数可以连接查询相应商品信息,注意在group中体现。 sum(商品数量) as total from tablea a left join tableb b on a.商品id = b.id group by a.商品id,b.name order by total desc
考虑的真全面
select productid,sum(productnum)as sum_count from product group by productid order by sum_count desc;
select 商品id , (select 商品名称 from 商品表 p where p.商品ID = x.商品ID) As 商品名称 , sum(商品数量) total from table x group by 商品id order by 3 desc
select * from t1,(select 商品id ,sum(商品数量) total from table group by 商品id order by total desc )t2 where t1.col=t2.col
select 商品id ,b.name as 商品名, --次数可以连接查询相应商品信息,注意在group中体现。
sum(商品数量) as total
from tablea a
left join tableb b on a.商品id = b.id
group by a.商品id,b.name
order by total desc
select 商品id ,b.name as 商品名, --次数可以连接查询相应商品信息,注意在group中体现。
sum(商品数量) as total
from tablea a
left join tableb b on a.商品id = b.id
group by a.商品id,b.name
order by total desc
考虑的真全面
select productid,sum(productnum)as sum_count
from product group by productid order by sum_count desc;
select 商品id ,
(select 商品名称 from 商品表 p where p.商品ID = x.商品ID) As 商品名称 ,
sum(商品数量) total from table x
group by 商品id
order by 3 desc