How to sum runningcount by year on to yearrunningcount SELECT ParentKEY, Quarters,…
- User
How to sum running_count by year on to year_running_count
SELECT Parent_KEY, Quarters, SUM(quarter_sum/gg_runing_count) OVER( PARTITION BY Year ) AS runing_count, SUM(year_sum/gg_year_runing_count) OVER( PARTITION BY string_field_14 ) AS year_runing_count FROM(SELECT *,COUNT( DISTINCT global_good) OVER( PARTITION By Quarters ) As quarter_sum,COUNT( DISTINCT global_good) OVER( PARTITION By Year ) As year_sum, COUNT(global_good_count) OVER( PARTITION BY Quarters ) AS gg_runing_count, COUNT(global_good_count) OVER( PARTITION BY Year ) AS gg_year_runing_count FROM(SELECT *, CASE when global_good is not null then 1 end as global_good_count, CASE when DATE(2021,10,01) <= date_field_8 and date_field_8 <= DATE(2022,09,30) then "2022" when DATE(2020,10,01) <= date_field_8 and date_field_8 <= DATE(2021,09,30) then "2021" when DATE(2019,10,01) <= date_field_8 and date_field_8 <= DATE(2020,09,30) then "2020"
END as Year, CASE when DATE(2022,07,01) <= date_field_8 and date_field_8 <= DATE(2022,09,30) then "2022,Q4" when DATE(2022,04,01) <= date_field_8 and date_field_8 <= DATE(2022,06,30) then "2022,Q3" when DATE(2022,01,01) <= date_field_8 and date_field_8 <= DATE(2022,03,31) then "2022,Q2" when DATE(2021,10,01) <= date_field_8 and date_field_8 <= DATE(2021,12,31) then "2022,Q1" when DATE(2021,07,01) <= date_field_8 and date_field_8 <= DATE(2021,09,30) then "2021,Q4" when DATE(2021,04,01) <= date_field_8 and date_field_8 <= DATE(2021,06,30) then "2021,Q3" when DATE(2021,01,01) <= date_field_8 and date_field_8 <= DATE(2021,03,31) then "2021,Q2" when DATE(2020,10,01) <= date_field_8 and date_field_8 <= DATE(2020,12,31) then "2021,Q1" when DATE(2020,07,01) <= date_field_8 and date_field_8 <= DATE(2020,09,30) then "2020,Q4" when DATE(2020,04,01) <= date_field_8 and date_field_8 <= DATE(2020,06,30) then "2020,Q3" when DATE(2020,01,01) <= date_field_8 and date_field_8 <= DATE(2020,03,31) then "2020,Q2" when DATE(2019,10,01) <= date_field_8 and date_field_8 <= DATE(2020,07,01) then "2020,Q1"
END as Quarters FROM (SELECT * FROMsincere-muse-138523.M_AND_E.Digital_Global_Goodas B Joinsincere-muse-138523.M_AND_E.Digital_Global_Good_repas A on A.PARENT_KEY=B.string_field_15))) - Assistant
- User
SELECT Parent_KEY,gg_year_runing_count,year_sum, Year, SUM(year_sum/gg_year_runing_count) OVER( PARTITION BY Year ) AS year_runing_count FROM(SELECT *,COUNT( DISTINCT global_good) OVER( PARTITION By Year ) As year_sum, COUNT(global_good_count) OVER( PARTITION BY Year ) AS gg_year_runing_count FROM(SELECT *, CASE when global_good is not null then 1 end as global_good_count, CASE when DATE(2021,10,01) <= date_field_8 and date_field_8 <= DATE(2022,09,30) then "2022" when DATE(2020,10,01) <= date_field_8 and date_field_8 <= DATE(2021,09,30) then "2021" when DATE(2019,10,01) <= date_field_8 and date_field_8 <= DATE(2020,09,30) then "2020"
END as Year, FROM (SELECT * FROMsincere-muse-138523.M_AND_E.Digital_Global_Goodas B Joinsincere-muse-138523.M_AND_E.Digital_Global_Good_repas A on A.PARENT_KEY=B.string_field_15))) ORDER BY Year asc - Assistant
Your modified query will sum the year_sum and gg_year_running_count columns by Year and display the result in the year_running_count column. The query also includes the Parent_KEY, gg_year_running_count, year_sum, and Year columns. Here's the updated query:
sql - User
How to a running value of the running count by year
- Assistant
To calculate the running value of the running count by year, you can modify the query as follows:
sql - User
SELECT list expression references column Parent_KEY which is neither grouped nor aggregated
- Assistant
To resolve the error "SELECT list expression references column 'Parent_KEY' which is neither grouped nor aggregated," you can add the 'Parent_KEY' column to the GROUP BY clause of the outermost SELECT statement. Here's the updated query:
sql - User
Column name Parent_KEY is ambiguous
- Assistant
If the column name 'Parent_KEY' is ambiguous, it means that the column exists in multiple tables involved in the query, and the database engine is unable to determine which table's column should be used. To resolve this ambiguity, you need to explicitly specify the table name or table alias for the 'Parent_KEY' column in the SELECT statement. Modify the query as follows:
sql