场景:
Column1 Column2
----------------
Test1 5
Test2 10
Test1 5
Test3 5
我想按Column1中的值检索column2顺序中的值总数
结果应该是
Column1 Column2
----------------
Test1 10
Test2 10
Test3 5
答案 0 :(得分:1)
您需要SUM()
和GROUP BY
和ORDER BY SUM() DESC
SELECT Column1, SUM(Column2) AS Column2
FROM TableName
GROUP BY Column1
ORDER BY SUM(Column2) DESC, Column1