简体   繁体   English

查询条件-Oracle SQL

[英]query condition - Oracle SQL

I wrote code only on transact sql . 我只在Transact sql上编写代码。 I want to write this query in oracle sql. 我想在oracle sql中编写此查询。 But it doesn't work . 但这没用。 the main problem that I can't write my select parameters in the where condition . 主要问题是我无法在where条件中编写选择参数。 How to avoid this problem . 如何避免这个问题。 My query , 我的查询

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

You need to use derived table/inline view: 您需要使用派生表/内联视图:

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....

or common table expression : 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