Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Soma em subconsultas no SQL Server


Tente isto:
SELECT ID, col1, col2, [Total] = (col1 + col2)
FROM (
    SELECT Id,
    (SELECT COUNT(*) FROM table1 LEFT JOIN table2 on ...) as col1,
    (SELECT COUNT(*) FROM table3 LEFT JOIN table4 on ...) as col2
    FROM [TABLE]) T

Espero que ajude.