Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL select with group and subquery
Message
From
10/07/2013 16:40:48
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
SQL select with group and subquery
Environment versions
SQL Server:
SQL Server 6.5 and older
Application:
Web
Miscellaneous
Thread ID:
01578149
Message ID:
01578149
Views:
67
Hi all -
I have this query which works OK.
select a.TipID, a.AMOUNT*1000 as OldProgram, a.FundType, a.Year, isnull(sum(b.amount),0) as AmountSpent, isnull(c.AMOUNT*1000,0) as NewProgram 
from TIP_ApprovedFunding a
left join TIP_Ledger b on a.tipid = b.tipid and a.fundtype=b.fundtype and a.year = b.fisyear
left join TIP_ProposedFunding c on a.tipid = c.tipid and a.fundtype=c.fundtype and a.year = c.year
where a.YEAR= 2013 
group by a.TipID,  a.amount, a.FundType, a.YEAR, c.amount
order by a.TipID
I need to take it one step further and filter the result to only the records where AmountSpent is > NewProgram. My attempts to do this have all failed. Apparently there needs to be a subquery or HAVING clause involved which I don't understand. Can someone help please?
Thanks
Next
Reply
Map
View

Click here to load this message in the networking platform