The question is simple: I want to do:
SELECT SUM((... a subquery that returns multiple rows with a single int value ...)) AS total;
How would I do that? I get an error saying that subquery returns more than one row. I need to have it in a subquery.
Here's an approach that should work for you:
SELECT SUM(column_alias)
FROM (select ... as column_alias from ...) as table_alias
And here's a specific dummy example to show the approach in action:
select sum(int_val)
from (
select 1 as int_val
union
select 2 as int_val
union
select 3 as int_val
) as sub;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With