Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create proc usp_GetHoldersWithBalanceHigherThan @balance decimal(18,4)
- as
- begin
- --Take the IDs of the accounts with total balance bigger than the given amount (@balance)
- with CET_AccountBalance as(
- select ah.Id, sum(a.Balance) Balance from AccountHolders ah
- left join Accounts a on a.AccountHolderId = ah.Id
- group by ah.Id
- having sum(a.Balance) > @balance
- )
- select ah.FirstName, ah.LastName from AccountHolders ah
- right join CET_AccountBalance ab on ab.Id = ah.Id
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement