sql >> Base de Datos >  >> RDS >> Sqlserver

Suma en subconsultas en SQL Server

Prueba esto:

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 ayude.