我有这张表temp_calpoints1
orderid processid uid ordervalue percent
1 1 16 33000 10
1 2 4 33000 10
1 3 5 33000 10
1 4 5 33000 20
1 5 4 700000 10
2 1 4 100000 10
2 2 4 100000 10
2 3 5 100000 10
2 4 4 100000 20
2 5 4 700000 10
2 6 1 700000 6
2 6 4 700000 6
2 6 16 700000 6
4 5 5 700000 10
5 1 16 700000 10
我想获得输出
ordervalue的百分比值 例如,在第一记录中10/100 * 33000 = 3300
我需要添加所有这些值并根据uid
对它们进行分组 uid totalvalue
1 xxx
4 xxx
5 xxx
16 xxx
我尝试了这个但是有些不能正常工作
SELECT
processid,
SUM(ordervalue) AS [TotalSales]
FROM [dbo].temp_calpoints1
GROUP BY [uid]
答案 0 :(得分:0)
尝试此选项
SELECT [uid], SUM(([percent] / 100.00) * ordervalue) AS total
FROM dbo.test46
GROUP BY [uid]
结果:
uid total
1 42000.000000
4 225300.000000
5 89900.000000
16 115300.000000
SQLFiddle上的演示