Question

Is there an elegant way to do this in MySQL:

SELECT (subquery1) AS s1, (subquery2) AS s2, (s1+s2) AS s3

or must I resort to

SELECT (subquery1) AS s1, (subquery2) AS s2, ((subquery1)+(subquery2)) AS s3

?

Thanks

EDIT: both subqueries yield integer results

Was it helpful?

Solution

You can use variables within MySQL


SELECT @query1:=(subquery) AS s1, @query2:=(subquery) AS s2, (@query1+@query2) AS s3

Still not that elegant. Perhaps you could elaborate on the subqueries so we could perhaps suggest better ways?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top