Oracle / SQL 00904. 00000 - “%s:无效标识符”

时间:2016-11-29 00:51:10

标签: sql oracle

我在sql和数据库方面仍然有点新鲜。我觉得我错过了一些非常简单的东西,但我似乎无法弄清楚为什么我会收到这个错误。

ORA-00904: "Total Pay": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

感谢任何帮助。

  with computed_pay as (select J.job_code,
                               case
                                 when J.pay_type = 'salary' then J.pay_rate
                                 when J.pay_type = 'wage' then J.pay_rate * 1920
                                 else null
                               end "Total Pay"
                          from job J),
       current_pay as (SELECT per_id,
                              "Total Pay",
                              primary_sector
                         FROM works
                         NATURAL JOIN job
                         NATURAL JOIN company
                         NATURAL JOIN job_profile),
       old_pay as (SELECT per_id,
                          "Total Pay",
                          primary_sector
                     FROM works
                     NATURAL JOIN job
                     NATURAL JOIN company
                     NATURAL JOIN job_profile),
       num_increase as (SELECT *
                          FROM current_pay C
                          WHERE EXISTS (SELECT I.per_id
                                          FROM old_pay I
                                          WHERE C.per_id = I.per_id) AND
                                "Total Pay" > all (SELECT "Total Pay"
                                                     FROM old_pay O
                                                     WHERE C.per_id = O.per_id)),
       num_decrease as (SELECT *
                          FROM current_pay C
                          WHERE EXISTS (SELECT I.per_id
                                          FROM old_pay I
                                          WHERE C.per_id = I.per_id) AND
                                "Total Pay" < all (SELECT "Total Pay"
                                                     FROM old_pay O
                                                     WHERE C.per_id = O.per_id))
select (case
          when (SELECT COUNT(*) FROM num_increase) <> 0 then
            (SELECT COUNT(*) FROM num_decrease) /
                (SELECT COUNT(*) FROM num_increase)
        end) as ratio 
  from dual;

1 个答案:

答案 0 :(得分:0)

我认为您打算使用computed_pa​​y代替作业,但您实际上并没有更改对作业的引用。

我也建议永远不要使用NATURAL JOIN。它使用列名来猜测如何连接表,如果你有通用列,如CREATED_ON或CREATED_BY,它将会中断,你最终会重写所有的SQL。