0

我想制作我的金额小于某个值的列。当我尝试这个时,查询运行

select LOSA_APP.app_ref_no AS "App.Ref.No.",
   LOSA_EXP_SUMM_Z.group_exp AS "Group Exposure Amount",
   LOSA_EXP_SUMM_Z.group_exp - 25000 AS "Less than",
   columns AS "some Name"
   columns AS "some Name"
from 
     losa_app LOSA_APP
INNER JOIN
    code_branch CODE_BRANCH
ON
    LOSA_APP.attend_branch = CODE_BRANCH.branch_id
....
where 
    LOSA_APP.app_status in ('A','R')
and
    ....
 or 
 (
    '&&aplication' = 'Enhancement' 
    and 
    (
        nvl(LOSA_APP.review_type, '-') IN ('Enhancement', 'Additional')  and nvl(LOSA_APP.review_freq, '-') IN ('Enhancement', 'New')
    )
);

但是,当我将行更改为 时LOSA_EXP_SUMM_Z.group_exp - 25000 AS "Less than"LOSA_EXP_SUMM_Z.group_exp < 25000 AS "Less than"我得到的错误是

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"
*Cause:    
*Action:
Error at Line: 3 Column: 34

第 3 行是LOSA_EXP_SUMM_Z.group_exp < 25000 AS "Less than". 为什么在我们使用时会运行它subtract sign并在 的情况下给出错误relational operator

谢谢

4

1 回答 1

1

If you want to use a relational operator in a SELECT then you will need to use it in a CASE statement similar to this:

select LOSA_APP.app_ref_no AS "App.Ref.No.",
   LOSA_EXP_SUMM_Z.group_exp AS "Group Exposure Amount",
   CASE 
        WHEN LOSA_EXP_SUMM_Z.group_exp < 25000 
        then 'true'
        else 'false' 
     end AS "Less than",
   columns AS "some Name"
   columns AS "some Name"
from losa_app LOSA_APP
INNER JOIN code_branch CODE_BRANCH
    ONLOSA_APP.attend_branch = CODE_BRANCH.branch_id
....
where  LOSA_APP.app_status in ('A','R')
and
    ....
 or 
 (
    '&&aplication' = 'Enhancement' 
    and 
    (
        nvl(LOSA_APP.review_type, '-') IN ('Enhancement', 'Additional')  and nvl(LOSA_APP.review_freq, '-') IN ('Enhancement', 'New')
    )
);

This will now return either a true or false if the record is less than 25000. You can change the return to whatever you need, including:

select LOSA_APP.app_ref_no AS "App.Ref.No.",
   LOSA_EXP_SUMM_Z.group_exp AS "Group Exposure Amount",
   CASE WHEN LOSA_EXP_SUMM_Z.group_exp < 25000 
            then LOSA_EXP_SUMM_Z.group_exp - 25000
        else LOSA_EXP_SUMM_Z.group_exp end AS "Less than",
   columns AS "some Name"
   columns AS "some Name"
from losa_app LOSA_APP
INNER JOIN code_branch CODE_BRANCH
    ONLOSA_APP.attend_branch = CODE_BRANCH.branch_id
....
where  LOSA_APP.app_status in ('A','R')
and
    ....
 or 
 (
    '&&aplication' = 'Enhancement' 
    and 
    (
        nvl(LOSA_APP.review_type, '-') IN ('Enhancement', 'Additional')  and nvl(LOSA_APP.review_freq, '-') IN ('Enhancement', 'New')
    )
);
于 2012-12-05T14:27:03.727 回答