iT邦幫忙

0

[MySQL]請問如何依照相同Order編號 , 使總價相加, 並且只輸出單一Order編號

https://ithelp.ithome.com.tw/upload/images/20210908/20140641EI5Kc0r1JD.png

提示: gropu BY +sum
0
jason
iT邦新手 4 級 ‧ 2021-09-08 16:27:36
最佳解答

補充 : 可以用DENSE_RANK()做排行

SELECT DENSE_RANK() OVER(ORDER BY SUM([總價]) DESC) AS NO, [Order] AS Order, SUM([總價]) AS Total_Price
FROM [Table_Name]
group by [Order]

其他還有row_number()、rank()等函式能用

3
firecold
iT邦新手 1 級 ‧ 2021-09-08 01:25:56
select Order as order_id, SUM('總價') as amount from table_name group by order_id
0

MSSQL

select [Order],SUM([總價]) Total
from Ordertable
group by [Order]
0
Hankz
iT邦新手 3 級 ‧ 2021-09-08 15:06:28

使用GROUP BY語句與SUM函數
DEMO

select order_num , SUM(total_price)
from sales
group by order_num;

我要發表回答

立即登入回答