Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The table_aliases method takes GROUP BY as an alias from CTE. #526

Open
cmistiloglou opened this issue Sep 4, 2024 · 0 comments
Open

The table_aliases method takes GROUP BY as an alias from CTE. #526

cmistiloglou opened this issue Sep 4, 2024 · 0 comments

Comments

@cmistiloglou
Copy link

cmistiloglou commented Sep 4, 2024

Using the method parser.tables_aliases it brings back GROUP BY as a table alias in MSSQL.

Tables Aliases: {'GROUP BY': '[Table1]', 't3': '[Table1]', 't4': '[Table2]', 't1': '[Table3]', 't2': '[Table4]'}

Executed sql query:

WITH [CTE1] AS (
    SELECT 
        [Col1], 
        MAX([Col2]) AS [MaxCol2]
    FROM 
        [Table1]
    GROUP BY 
        [Col1]
)
SELECT 
    t1.[ColA] AS [PortfolioCode], -- Portfolio unique identifier
    t2.[ColB] AS [InstrumentCode],  -- Instrument unique identifier
    SUM(t3.[Qty1]) AS [OutstandingQuantity], 
    SUM(t3.[Qty2]) AS [InstrumentValuation], 
    t4.[Code] AS [ValuationCurrency], 
    t3.[DateCol] AS [RefDate]
FROM 
    [Table1] t3
JOIN [CTE1] t1 ON t3.[Col1] = t1.[Col1] AND t3.[DateCol] = t1.[MaxCol2]
JOIN [Table2] t4 ON t4.[ID] = t3.[Col2]
JOIN [Table3] t1 ON t1.[ID] = t3.[Col3]
JOIN [Table4] t2 ON t2.[ID] = t3.[Col4] AND (t2.[Code] LIKE @Param1) 
WHERE 
    t3.[Qty1] <> 0
	  
GROUP BY
    t1.[ColA],
    t2.[ColB],
    t4.[Code],
    t3.[DateCol];

Version: sql_metadata==2.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant