sql >> Database teknologi >  >> RDS >> Mysql

Reference understøttes ikke på gruppefunktion

Du kan ikke bruge de kolonnealiasser, du definerede i en forespørgsel i den samme forespørgsel. Prøv noget i stil med følgende:

SELECT   *,
         TRIP1 / FUEL1 AS ECON1,
         TRIP31 / FUEL31 AS ECON31,
         OTHER COLUMNS....
FROM
(
    SELECT    v.V_VEHICLEID, 
              v.V_LICENSENO,
              ROUND((MAX(IF(DAY(WP_DATETIME) = 1, WP_ODOMETER, NULL)) - MIN(IF(DAY(WP_DATETIME) =     1,     WP_ODOMETER, NULL))) / 1000) AS TRIP1,
              ROUND(MAX(IF(DAY(WP_DATETIME) = 1, WP_FUELREAD, NULL)) - MIN(IF(DAY(WP_DATETIME) = 1,     WP_FUELREAD, NULL)),2) AS FUEL1,
              ROUND((MAX(IF(DAY(WP_DATETIME) = 31, WP_ODOMETER, NULL)) - MIN(IF(DAY(WP_DATETIME) = 31, WP_ODOMETER, NULL))) / 1000) AS TRIP31,
              ROUND(MAX(IF(DAY(WP_DATETIME) = 31, WP_FUELREAD, NULL)) - MIN(IF(DAY(WP_DATETIME) = 31, WP_FUELREAD, NULL)),2) AS FUEL31,
              OTHER COLUMNS...
    FROM      VEHICLES v
    JOIN      WAYPOINTS wp
    ON        wp.WP_VEHICLEID = v.V_VEHICLEID
    WHERE     MONTH(wp.WP_DATETIME) = '6' 
    AND       v.V_USER = 'tc'
    GROUP BY  wp.WP_VEHICLEID
) t


  1. Jeg droppede general_log-tabellen, hvordan opretter jeg den igen?

  2. Hvordan kan vi adskille LEFT OUTER JOIN vs Left Join

  3. ScaleGrid shortlistet til Cloud Awards-programmet 2017-2018

  4. TypeScript-fejl ved brug af Op.between i Sequelize with Dates