Correct sql with error [Code: 7321, SQL State: 53003] SQL Anywhere Error -149: Function…
- User
Correct sql with error [Code: 7321, SQL State: 53003] SQL Anywhere Error -149: Function or column reference to 'DATE_ID' must also appear in a GROUP BY without grouping by DATE_ID
SELECT BSC as [BSC_Name], DATE_ID, CELL_NAME as [Cell_Name], CELL_NAME_NEIGHBOUR as [Neighbour_Cell_Name], SUM(HOVERCNT) as [2G Attempts_for_14_Days] FROM DC.DC_E_BSS_CELL_ADJ_RAW WHERE DATE_ID >= DATEADD(DAY,-14,GETDATE()) GROUP BY BSC, CELL_NAME, CELL_NAME_NEIGHBOUR; - Assistant
The error occurs because the column
DATE_IDis not included in theGROUP BYclause. To correct the error, you need to includeDATE_IDin theGROUP BYclause. Here's the corrected SQL statement:SELECT BSC as [BSC_Name], DATE_ID, CELL_NAME as [Cell_Name], CELL_NAME_NEIGHBOUR as [Neighbour_Cell_Name], SUM(HOVERCNT) as [2G Attempts_for_14_Days] FROM DC.DC_E_BSS_CELL_ADJ_RAW WHERE DATE_ID >= DATEADD(DAY,-14,GETDATE()) GROUP BY BSC, DATE_ID, -- Include DATE_ID in the GROUP BY clause CELL_NAME, CELL_NAME_NEIGHBOUR; - User
I want output data aggregated for all 14 days
- Assistant
To aggregate the data for all 14 days, you can remove the
DATE_IDcolumn from theSELECTclause and theGROUP BYclause. Here's the modified SQL statement:SELECT BSC as [BSC_Name], CELL_NAME as [Cell_Name], CELL_NAME_NEIGHBOUR as [Neighbour_Cell_Name], SUM(HOVERCNT) as [2G Attempts_for_14_Days] FROM DC.DC_E_BSS_CELL_ADJ_RAW WHERE DATE_ID >= DATEADD(DAY, -14, GETDATE()) GROUP BY BSC, CELL_NAME, CELL_NAME_NEIGHBOUR;In this query, the data will be aggregated for all 14 days, but the specific
DATE_IDvalues will not be included in the result.