sql >> Database teknologi >  >> RDS >> Sqlserver

Forkert syntaks nær nøgleordet 'GROUP' I SQL

Du skal navngive din underforespørgsel:

DECLARE @avg_volume INT
 SELECT @avg_volume = ISNULL(AVG(Total_Volume), 0)
 FROM   ( SELECT    station_id ,
                    DATEPART(Year, date_time) AS YEAR ,
                    DATEPART(month, date_time) AS MONTH ,
                    CONVERT(DATE, date_time) AS DATE ,
                    DATENAME(weekday, date_time) AS weekday ,
                    SUM(volume) AS Total_volume
          FROM      rvtcs_data_aggregated_hourly
          GROUP BY  station_id ,
                    CONVERT(DATE, date_time) ,
                    DATEPART(month, date_time) ,
                    DATEPART(Year, date_time) ,
                    DATENAME(weekday, date_time)

        ) AnyNameYouLikeButYouHaveToGiveOne --<-- Here

 GROUP BY station_id ,
        CONVERT(DATE, date_time) ,
        DATEPART(month, date_time) ,
        DATEPART(Year, date_time) ,
        DATENAME(weekday, date_time)
 ORDER BY DATEPART(Year, date_time) ,
        DATEPART(month, date_time) ,
        CONVERT(DATE, date_time)

 SELECT @avg_volume


  1. Databaseydelse:filtrering på kolonne i forhold til separat tabel

  2. Hvad betyder "LANGUAGE 'plpgsql' VOLATILE"?

  3. Parse fejl:syntaksfejl, uventet T_ELSE

  4. jboss 7 oracle datakilde konfiguration