Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sum two select statements in sql

Tags:

sql

sql-server

I'm looking to produce the sum of these two select statements:

select sum(amount) as hr from friday.dbo.FMDR_Friday_CSV where [Account #] like 4010

select sum(amount) as hr from friday.dbo.FMDR_Friday_CSV where [Account #] like 4060

I've tried putting a union between them, which only serves to produce the two results in the same results window.

Thanks for any help, I'm an absolute beginner.

like image 216
AdMac Avatar asked Dec 22 '25 14:12

AdMac


1 Answers

In case you want to use multiple selects (maybe if other tables are involved)

select ((select sum(hours) from foo1) +
        (select sum(hours) from foo2)) as totalHours
like image 82
farbiondriven Avatar answered Dec 24 '25 03:12

farbiondriven



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!