Assuming a table level with columns level_id and level_name
I have a virtual table in my SQL Server 2016 query:
This is not a real query - I've simplified it as much as possible to illustrate the error
SELECT
LEVEL .level_id,
LEVEL .level_name
FROM
LEVEL,
((SELECT
LEVEL_ID AS lev_sum_level_id
FROM
LEVEL
GROUP BY
level_id) AS lev_sum
JOIN
(SELECT
LEVEL_ID AS lev_det_level_id
FROM
LEVEL
GROUP BY
level_id) AS lev_det ON (lev_sum_level_id = lev_det_level_id)
) AS totals
The syntax error is on the line AS totals.
Msg 156, Level 15, State 1, Line 35
Incorrect syntax near the keyword 'AS'
Why is SQL Server not allowing this syntax? Seems fine if I simplify the virtual table query. Postgres allows it as-is