2019-03-04
閱讀量:
1665
請問獲取訂單金額前10的用戶的SQL怎么寫?
問題描述:
有如下兩張示例表
訂單金額等于 orderinfo
表里 price*count
,每個訂單有多個商品,每個用戶也可能有多個訂單。
請問如何通過SQL語句獲取訂單總金額排前10的用戶?

解決方法:
訂單:

orderinfo:

select sum(a.price * a.count) as total, a.order_id, b.user_id
from `orderinfo` as a, `order` as b
where a.order_id=b.id
group by a.order_id
order by total DESC
limit 10;






評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
0條評論
0條評論
0條評論