查询y子查询中的标识符无效

时间:2018-12-09 13:53:14

标签: oracle

以下查询返回错误:

ORA-00904: "C"."CHARGEDATE": invalid identifier 
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error en la línea: 6, columna: 58

查询如下:

Select
    c.idChargeStation,
    c.idVehicleUnit,
    round(cc.totalTiempo/cc.totalCargas, 2) AS media,
    v.versionNameVU, 
    c.chargeDate, 
    p.firstName, 
    p.lastName
FROM 
    Charge c, 
    VehicleUnit v, 
    Person p,
    (
        SELECT 
            idChargeStation, 
            idVehicleUnit, 
            chargeDate, 
            SUM(totalPluggedTime) AS totalTiempo, 
            count(*) AS totalCargas
        FROM Charge  
        WHERE 
            idChargeStation =  c.idChargeStation 
            AND idVehicleUnit = c.idVehicleUnit
            AND chargeDate = c.chargeDate
    ) cc
WHERE
    c.idVehicleUnit = v.idVehicleUnit
    AND v.idClient = p.idPerson
    HAVING media > 600
    HAVING round(c.powerKwH/c.KmFromLast, 2) > 1.00
Order by c.chargeDate DESC;

共有3个表格:ChargeVehicleUnitPerson

  • idVehicleUnitVehicleUnitidVehicleUnit = idVehicleUnit)的外键

  • idClientPersonidClient = idPerson)的外键

我添加信息,组成每个表的前10条记录所涉及的表。

餐桌费: Table Charge

Table VehicleUnit: Table VehicleUnit

餐桌人物: Table Person

查询必须返回idChargeStation,idVehicleUnit,费用表的chargeDate字段,totalPluggedTime平均,vehicleUnit表的versionNameVU字段以及Person表的firstName和lastName字段。

平均值通过以下方式获得: SUM(totalPluggedTime)AS totalTime count(*)AS totalLoads <-----总子查询记录,其中idChargeStation,idVehicleUnit和chargeDate相等。 将这些数据放入主查询回合中(cc.totalTime / cc.totalLoads,2)AS平均

1 个答案:

答案 0 :(得分:0)

好吧,我在查询中遇到了一些不好的事情,但是我已经解决了,也非常感谢,我提出了正确的查询

    select c.idVehicleUnit, round(sum(c.totalPluggedTime)/count(*), 2) AS media, v.versionNameVU, p.firstName, p.lastName
    FROM charge c 
    inner join charge cc on c.idVehicleUnit = cc.idVehicleUnit  
    inner join vehicleUnit v on cc.idVehicleUnit = v.idVehicleUnit AND c.idVehicleUnit = cc.idVehicleUnit
    inner join person p on v.idClient = p.idPerson
    group by c.idVehicleUnit, v.versionNameVU, p.firstName, p.lastName, c.powerKwH, c.KmFromLast
    HAVING round(sum(c.totalPluggedTime)/count(*), 2) > (Select round(6*(sum(totalPluggedTime)/count(*)), 2) from charge)
    AND round(c.powerKwH/c.KmFromLast, 2) > 1.00 
    ORDER BY c.chargeDate DESC;