我有以下表格
Name Val
Test1 $100.00
Test2 $200.00
Test3 $300.00
Test4 $400.00
Test5 $500.00
我能够通过组检索val:
SELECT Name,sum(Val) FROM Synthese WHERE Name IN ( 'Test1' , 'Test2' , 'Test3') GROUP BY Name
得到以下输出:
Name Val
Test1 $100.00
Test2 $200.00
Test3 $300.00
但我不知道该怎么做:
sum(val)/(val(Test1)+val(Test2)+val(Test3))
数值示例:
100/(100+200+300)
200/(100+200+300)
300/(100+200+300)
我该怎么办?
SELECT Name,
sum(Val)/(SELECT sum(Val) FROM Synthese WHERE Name IN('Test1','Test2','Test3'))
FROM Synthese
WHERE Name IN('Test1','Test2','Test3')
GROUP BY Name