Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create A Running Total In A Query
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01327963
Message ID:
01328064
Views:
20
I can't get this running total query to work.
SELECT	OrderId,
		UnitPrice,
		Quantity,
		UnitPrice * Quantity AS RowAmt,
		(SELECT SUM(UnitPrice * Quantity) AS RunningTot
			FROM [Order Details]
			WHERE OrderId = o.OrderId
	FROM [Order Details] o
I get "Incorrect syntax near the keyword 'FROM'." on the inner query.




>>I have a field called DollarAmt on a report, along with a running total of DollarAmt into a field called Ord_Tot:
>>
>> DollarAmt  Ord_Tot
>>-------------------------------
>>   659.75       659.75
>> 9,566.20    10,225.95
>> 3,380.00    13,605.95
>> 3,450.00    17,055.95
>>13,316.00    30,371.95
>>
>>
>>
>>How do I create this running total in a query?
>
>Glad you asked. I knew it, give me a sec.
>
>http://www.sqlteam.com/article/calculating-running-totals
>
>I solved this problem myself on the interview, but I forgot my own solution (think it was 2).
>
>Just google "Running Total SQL Server" and you'll find plenty of articles.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform