繁体   English   中英

查询条件-Oracle SQL

[英]query condition - Oracle SQL

我只在Transact sql上编写代码。 我想在oracle sql中编写此查询。 但这没用。 主要问题是我无法在where条件中编写选择参数。 如何避免这个问题。 我的查询

 select t.*, 
 count(*) over(partition by t.el1_code) cnt ,
 count(*) over(partition by t.el1_code, t.el1_valid) cnt1 ,
 concat(t.el1_name,t.el1_sname) str,
 max(concat(t.el1_name,t.el1_sname)) over(partition by t.el1_code) str_check
 from tasuser.coda_element_1 t
 )tt


 —where tt.cnt>1 and (tt.el1_valid=0 or (tt.el1_valid=1 and cnt=cnt1 and     
  str<>str_check) )
  where not  (tt.cnt>1 and (tt.el1_valid=0 or (tt.el1_valid=1 and    
  cnt=cnt1       and 
  str<>str_check)))

您需要使用派生表/内联视图:

SELECT *
FROM (
 select t.*, 
 count(*) over(partition by t.el1_code) cnt ,
 count(*) over(partition by t.el1_code, t.el1_valid) cnt1 ,
 concat(t.el1_name,t.el1_sname) str,
 max(concat(t.el1_name,t.el1_sname)) over(partition by t.el1_code) str_check
 from tasuser.coda_element_1 t
 )  tt
WHERE tt.conditions....

common table expression

WITH cte AS (
select t.*, 
     count(*) over(partition by t.el1_code) cnt ,
     count(*) over(partition by t.el1_code, t.el1_valid) cnt1 ,
     concat(t.el1_name,t.el1_sname) str,
     max(concat(t.el1_name,t.el1_sname)) over(partition by t.el1_code) str_check
     from tasuser.coda_element_1 t

)
SELECT *
FROM cte
WHERE conditions ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM