计数比较问题

时间:2018-07-12 12:29:11

标签: sql oracle

早上好,我无法使以下查询正常工作,我从

开始
select A.equipment_id,
B.vendor_name,
    B.vendor_part_number,
    C.clli_code,
    (select count(*) from TABLE D where equipment_spec_id = 
B.equipment_spec_id) as Spec_PAs,
    (select count(*) from TABLE E where equipment_id = A.equipment_id) as 
Eqp_PAs,
    (select count(*) from TABLE F where equipment_spec_id = 
B.equipment_spec_id) as Spec_MPs,
    (select count(*) from TABLE G where equipment_id = A.equipment_id) as 
Eqp_MPs

from
    TABLE A 
    TABLE B,
    TABLE C
    where
A.equipment_spec_id = B.equipment_spec_id
and A.location_id = C.location_id
HAVING  Spec_PAs <> Eqp_PAs
order by 4,2,3 

但我收到错误ORA-00904:“ EQP_MPS”:无效的标识符

所以我尝试了

SELECT * FROM (select A.equipment_id,
B.vendor_name,
    B.vendor_part_number,
    C.clli_code,
    (select count(*) from TABLE D where equipment_spec_id = 
B.equipment_spec_id) as Spec_PAs,
    (select count(*) from TABLE E where equipment_id = A.equipment_id) as 
Eqp_PAs,
    (select count(*) from TABLE F where equipment_spec_id = 
B.equipment_spec_id) as Spec_MPs,
    (select count(*) from TABLE G where equipment_id = A.equipment_id) as 
Eqp_MPs

from
    TABLE A 
    TABLE B,
    TABLE C)
    where
A.equipment_spec_id = B.equipment_spec_id
and A.location_id = C.location_id
HAVING  Spec_PAs <> Eqp_PAs
order by 4,2,3   

ERROR: ORA-00904: "C"."LOCATION_ID": invalid identifier

答案可能很简单。任何帮助都非常感谢

1 个答案:

答案 0 :(得分:-1)

表A后缺少逗号

尝试更改此内容

from
    TABLE A 
    TABLE B,
    TABLE C)
    where

对此

    from
    TABLE A, 
    TABLE B,
    TABLE C)
    where