February 23, 2011 at 10:08 am
I have this other scenario:
Select a.Id,
(Select Sum(b.quantity) from TableB b from b.Id=a.Id) AS Total,
(Select Sum(c.quantity) from TableC c from c.Id=a.Id) AS Total2,
(Total*Total2) as GranTotal from TableA a
where GranTotal>100
I can't use the columns computed with the subquery, so I can multiply and get another column.
Is there a way I can get this work?
February 23, 2011 at 10:11 am
Something like this.
Select a.Id, Sum(b.quantity) as Total, Sum(c.quantity) as Total2, Sum(b.quantity) * Sum(c.quantity) as GranTotal
from TableA a
join TableB b on b.Id = a.Id
join TableC c on c.Id = a.Id
group by a.Id
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 23, 2011 at 10:48 am
Thanks Sean, it helped me!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply