2012-12-05 29 views
0

我想使我的數量小於某個值的列。當我嘗試這一點,在查詢運行我們可以在select子句中使用關係運算符

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的情況下發生錯誤?

感謝

回答

1

如果你想使用一個SELECT關係運算符,那麼你將需要使用它在CASE聲明與此類似:

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') 
    ) 
); 

現在,這將返回一個truefalse如果記錄小於25000.您可以根據需要更改退貨,包括:

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') 
    ) 
); 
相關問題