MySQL: sum of subclassed columns

Is there an elegant way to do this in MySQL:

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

or should I resort to

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

?

thanks

EDIT: both subqueries return integer results

+3
source share
1 answer

You can use variables in MySQL


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

Still not so elegant. Perhaps you could develop subqueries so that we can offer better ways?

+3
source

Source: https://habr.com/ru/post/1712269/


All Articles