簡體   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