首页 > 解决方案 > ORA-00920: 第一次选择中的关系运算符无效

问题描述

嗨,请参考我必须显示的共享要求。错误发生在两个 count 以下的语句的 bcoz 中。我必须分两个cnt

在此处输入图像描述

 of_study_sites_without_rand_subj_gt AS
(
SELECT 
            tu.tu_status, tu.tr_no,
          case when ((asswors- SSWORGT30) then 'of_study_sites_without_rand_subject<30_days' END) SSW0RLT30
          , case when ((asswors- SSWORGT60) then 'of_study_sites_without_rand_subject<30_days' END) SSW0RLT60
          , case when ((asswors- SSWORGT90) then 'of_study_sites_without_rand_subject<30_days' END) SSW0RLT90
            from
( SELECT 
            tu.tu_status, tu.tr_no,           
   COUNT ( CASE WHEN tue.fst_init_vst_act_dt IS NOT NULL THEN tr.tr_alias_cd END ) act_study_site_init,
   COUNT ( CASE WHEN tue.fst_subj_rnd_act IS NOT NULL AND tu.tu_status= 'recruiting' THEN tr.tr_alias_cd END ) actual_with_rnd_rec,
 CASE WHEN (((act_study_site_init) - (actual_with_rnd_rec) AND tu.tu_status= 'nonrecruiting' then 'act_study_site_without_rnd_subj' END) asswors,
  CASE WHEN tue.fst_subj_rnd_act IS NULL then trunc(sysdate)- trunc(tue.fst_init_vst_act_dt )
      else  trunc ( tue.fst_subj_rnd_act ) - trunc ( tue.fst_init_vst_act_dt )
            END daycal,          
    case when daycal>=30 then count(tr.tr_alias_cd) END SSWORGT30 --of study sites without randomised subject ≥ 30 days
           , case when daycal>=60 then count(tr.tr_alias_cd) END SSWORGT60  --of study sites without randomised subject ≥ 60 days
           , case when daycal>=30 then count(tr.tr_alias_cd) END SSWORGT90  --of study sites without randomised subject ≥ 90 days            
  FROM da_cox.dm_ctm_tu tu      
        INNER JOIN da_cox.dm_ctm_tr tr ON tr.tr_no = tu.tr_no
        LEFT OUTER JOIN da_cox.df_ctm_tu_evnt tue 
ON tue.curr_flg = 1
   AND tue.tu_id = tu.tu_id
 WHERE
        tu.curr_flg = 1 /* Study sites that have been cancelled after initiation are counted as initiated */
    GROUP BY
        tu.tr_no,
        tu.tu_status,
        tr.tr_alias_cd

第一次选择时出错

case when ((asswors- SSWORGT30) then 'of_study_sites_without_rand_subject<30_days' END) SSW0RLT30

标签: oracle

解决方案


ORA-00920: 无效的关系运算符

此错误消息表明问题出在这部分语句中:

when ((asswors- SSWORGT30) then

你有一个测试,但没有条件。该声明期望类似

when ((asswors- SSWORGT30) <= 30 then

也就是说,如果给定总和的结果小于或等于 30,您的 case 语句将返回您在 THEN 之后拥有的字符串。


推荐阅读