久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

創(chuàng)建 Oracle 視圖以根據(jù)條件比較數(shù)據(jù)

create Oracle View to compare data based on conditions(創(chuàng)建 Oracle 視圖以根據(jù)條件比較數(shù)據(jù))
本文介紹了創(chuàng)建 Oracle 視圖以根據(jù)條件比較數(shù)據(jù)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我有下表:

    CREATE TABLE
        IS_ID
        (        
            FUND_ISIN VARCHAR2(12) NOT NULL,
            FUND_QUOTE_CRNY VARCHAR2(5),       
            MEMBER_DESCR VARCHAR2(5),
            MEMBER_RATIO NUMBER(19,8),
            ALLOCATIONASSETTYPE VARCHAR2(100)
        );
    
    CREATE TABLE
        IS_ID_TST
        (        
            FUND_ISIN VARCHAR2(12) NOT NULL,
            FUND_QUOTE_CRNY VARCHAR2(5),       
            MEMBER_DESCR VARCHAR2(5),
            MEMBER_RATIO NUMBER(19,8),
            ALLOCATIONASSETTYPE VARCHAR2(100)
        );

    

我想創(chuàng)建這樣的視圖:

  1. 對于兩個表中共同的 fund_isin 字段值,檢查 member_ratio 字段的 member_descr = 'O' 并獲取所有表中的 fund_isin 行,其中 member_ratio 字段值較低.對于 member_descr = 'O',如果 IS_ID_TST 表中的 member_ratio 對于任何 fund_isin 小于 0,則總是取IS_ID_TST表中的所有數(shù)據(jù)(在這種情況下,我們不需要比較IS_ID表中的數(shù)據(jù),因?yàn)槌蓡T比例低)

  1. for common fund_isin field value from both tables, check the member_ratio field for member_descr = 'O'and take all the rows for fund_isin from table where member_ratio field value is low. For member_descr = 'O', if the member_ratio in IS_ID_TST table is less than 0 for any fund_isin then always take all the data from IS_ID_TST table(in this case we dont need to compare data from IS_ID table for low member ratio)

如果 fund_isin 存在于一個表中但不存在于另一個表中,則獲取所有這些行(雙向).

if the fund_isin exist in one table but not in another then take all those rows(bidirectional).

對于所有其他 fund_isin,僅從表 IS_ID_TST 表中獲取所有這些行(這可能涵蓋第 1 點(diǎn)和第 2 點(diǎn))

for all the other fund_isin, take all those rows only from table IS_ID_TST table(this might cover in point 1 and 2 )

推薦答案

您能否檢查以下查詢,我已經(jīng)在 with 子句中制作了所有案例,然后將其結(jié)合起來.

Could you check following query, I have made all cases within with clause and then make union out of it.

- 通過聊天與 OP 討論和澄清

我們不再需要 full join 并且通過根據(jù)每種情況訪問表來重寫它.

We do not need full join any more and by accessing the table per each case it is re-written.

-- case 1
-- when fund_isin with member_ratio = 'O' present in both is_id and is_id_tst table
-- and the value of is_id.member_ratio < is_id_tst.memebr_ratio
-- logic --
-- the from clasuse says take all the records from is_id table 
-- by corelate the fund_isin (t1.fund_isin = t.fund_isin)
-- the subquery then finds record by joining both table is_id and is_id_tst for member_ratio = 'O'
-- and where the member_ratio is smaller (is_id_tst.member_ratio > is_id.member_ratio)
-- extra condition on is_id_tst table is the member_ratio value should be greater than 0 for member_descr='O'
WITH ratio_lower_is_id
AS
(SELECT *
   FROM is_id t
  WHERE EXISTS 
  (SELECT 1
     FROM is_id_tst t2
     JOIN is_id t1
       ON t2.fund_isin = t1.fund_isin
    WHERE t1.fund_isin = t.fund_isin
      AND t2.member_descr = 'O'
      AND t1.member_descr = 'O'
      AND t2.member_ratio > 0
      AND t2.member_ratio > 
          t1.member_ratio)
),
-- case 2
-- applies the same logic as in case 1 but then take records from is_id_tst table
-- where the member_ratio having lower value for record with member_descr='O'
-- in comparison with the record present in is_id table for memebr_descr='O'
ratio_lower_is_id_tst
AS
(SELECT *
   FROM is_id_tst t
  WHERE t.member_ratio > 0
    AND EXISTS 
  (SELECT 1
     FROM is_id t2
     JOIN is_id_tst t1
       ON t2.fund_isin = t1.fund_isin
    WHERE t1.fund_isin = t.fund_isin
      AND t2.member_descr = 'O'
      AND t1.member_descr = 'O'
      AND t2.member_ratio > 
          t1.member_ratio)
),
-- case 3
-- take all records from is_id_tst table for all each unique fund_isin 
-- where the member_ratio value is < 0 for record member_descr='O'
-- and is avaialble in is_id_tst table irrespective of what record for the same
-- fund_isin available in is_id table
ratio_minus_is_id_tst
AS
(SELECT *
   FROM is_id_tst t
  WHERE EXISTS 
  (SELECT 1
     FROM is_id_tst t1
    WHERE t1.fund_isin = t.fund_isin
      AND t1.member_descr = 'O'
      AND t1.member_ratio < 0)
),
-- case 4
-- take all the records from is_id table 
-- where the fund_isin is not available in is_id_tst table
only_in_is_id
AS
(
SELECT *
  FROM is_id t1
 WHERE NOT EXISTS
   (SELECT 1 
      FROM is_id_tst t2
     WHERE t2.fund_isin = t1.fund_isin)
),
-- case 5
-- take all the records from is_id_tst table
-- where the fund_isin is not available in is_id table
only_in_is_id_tst
AS
(
SELECT *
  FROM is_id_tst t1
 WHERE NOT EXISTS
   (SELECT 1 
      FROM is_id t2
     WHERE t2.fund_isin = t1.fund_isin)
)
-- finally once all the sets as per each case available
-- take each of them and do a union all for the final result set
-- one level sub query required only if we want to sort the result otherwise can be removed
-- and only union all of all sets from with clause is enough
select *
  from 
(
-- case1
select *
  from ratio_lower_is_id
union all
-- case 2
select *
  from ratio_lower_is_id_tst
union all
-- case 3
select *
  from ratio_minus_is_id_tst
union all
-- case 4
select *
  from only_in_is_id
union all
-- case 5
select *
  from only_in_is_id_tst
)
order by fund_isin;

這篇關(guān)于創(chuàng)建 Oracle 視圖以根據(jù)條件比較數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉(zhuǎn)換為“2016-07-01 13:12:22小時格式?)
is there a quot;splitquot; function in t-sql for a SELECT query(有沒有“分裂?用于 SELECT 查詢的 t-sql 中的函數(shù))
UNDOCUMENTED FEATURE when SELECT in VARCHAR with trailing whitespace SQL Server(在 VARCHAR 中使用尾隨空格 SQL Server SELECT 時的未記錄功能)
How to make SQLite SELECT query in C correctly?(如何在 C 中正確地進(jìn)行 SQLite SELECT 查詢?)
Create an Apex form with multiple pages(創(chuàng)建包含多個頁面的 Apex 表單)
How do I supply the FROM clause of a SELECT statement from a UDF parameter(如何從 UDF 參數(shù)提供 SELECT 語句的 FROM 子句)
主站蜘蛛池模板: 国产精品三级久久久久久电影 | 成人国产精品入口免费视频 | 国产视频三区 | 国产片侵犯亲女视频播放 | 黄色大片在线视频 | 精品一区二区三区av | 久久一区二区av | 天天弄天天操 | 欧美日韩在线免费观看 | 国产视频欧美 | 激情五月婷婷丁香 | 日韩和的一区二区 | av一区二区三区四区 | 亚洲精品一区二区三区在线 | 欧美午夜精品理论片a级按摩 | 亚洲国产黄色av | 日日夜夜精品视频 | 国产激情一区二区三区 | 日本午夜免费福利视频 | 男女又爽又黄视频 | 成人黄色av网址 | 日本精品视频在线观看 | 少妇无套高潮一二三区 | 日本精品视频 | av免费网站在线观看 | 成人久久18免费网站 | 高清18麻豆 | 久久精品福利视频 | 成人国产免费视频 | 亚洲天堂999 | 涩涩视频在线观看 | 五月天综合影院 | 伊人无码高清 | 久久久精品网站 | 国产精品美女一区二区三区 | 日韩不卡一区二区三区 | 久草精品视频 | 一级黄色毛片免费 | 久久最新精品 | 欧美人妇做爰xxxⅹ性高电影 | 国产欧美视频一区二区三区 |