无效的标识符 - oracle

时间:2012-07-22 02:24:30

标签: oracle11g

当我运行下面的查询时,我收到此消息:

SQL错误:ORA-00904:“B”。“MEMBERS_COUNT”:标识符无效 00904. 00000 - “%s:无效标识符”

select pt.paym_type_name, pt.dvd_allowed, b.members_count
from payment_type pt
where paym_type_id in (select paym_type_id
                        from (SELECT paym_type_id, 
                                     count(paym_type_id) as members_count
                              FROM user_payment
                              WHERE (paym_type_id=1   OR
                                     paym_type_id=2   OR
                                     paym_type_id=3)  AND 
                                     SYSDATE <= (ADD_MONTHS(paym_date, 12) ) 
                              GROUP BY paym_type_id
                              ORDER BY MEMBERS_COUNT DESC) b
                        where rownum=1)
;

我不明白为什么。我该如何解决?我需要在末尾添加MEMBERS_COUNT列。

1 个答案:

答案 0 :(得分:0)

select pt.paym_type_name, pt.dvd_allowed, b_outer.members_count
from payment_type pt,
    (select paym_type_id,members_count
      from (SELECT paym_type_id, 
                   count(paym_type_id) as members_count
             FROM user_payment
            WHERE (paym_type_id=1   OR
                   paym_type_id=2   OR
                   paym_type_id=3)  AND 
                   SYSDATE <= (ADD_MONTHS(paym_date, 12) ) 
                   GROUP BY paym_type_id
                   ORDER BY MEMBERS_COUNT DESC) b_inner
                   where rownum=1) b_outer
where paym_type_id =b_outer.paym_type_id