I have a dynamic query:
ID Name Num
------------
22 A 2
22 B 3
23 C 1
23 D 2
23 E 2
How to create a dynamic query to calculate the total like below?
ID Name Num Total
-----------------
22 A 2 7 <=> (2*2)+3
22 B 3 11 <=> (3*3)+2
23 A 1 5 <=> (1*1)+2+2
23 B 2 7 <=> (2*2)+1+2
23 C 2 7 <=> (2*2)+2+1
The Total equals to Num multiply by itself, and add all Nums that has the same ID.
Total=(Num*Num)+Nums Where ID = ID
Here is my query:
Select ID, Name, Num, (Num*Num)+Num as Total
Where ID = 1
My query returns incorrect Total.
Can you please help?
Thanks.