Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Somma sulle sottoquery su SQL Server

Prova questo:

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

Spero di esserti stato d'aiuto.