2021年5月5日星期三

Why do we need nested Select statement?

SELECT  A.country          ,A.market          ,SUM(COALESCE(A.sales_value,0)) AS local_currency_sales  FROM   (      SELECT  country              ,market              ,local_currency_sales      FROM TABLE   ) A  GROUP BY  A.country           ,A.market  

The above is the pseudo code I am referring to. I am new to SQL and would like to ask the reason that if there is a need to have a nested Select like this above? I tried to remove the nested Selected and it throws an error: country must appear in the Group By Clause. What I would like to know is that intuitively, the below should work even with Group by

SELECT  A.country          ,A.market          ,SUM(COALESCE(A.sales_value,0)) AS local_currency_sales        FROM TABLE A  GROUP BY  A.country           ,A.market  
https://stackoverflow.com/questions/67411060/why-do-we-need-nested-select-statement May 06, 2021 at 10:27AM

没有评论:

发表评论