当前在线人数17035
首页 - 分类讨论区 - 电脑网络 - 数据库版 -阅读文章
未名交友
[更多]
[更多]
文章阅读:Re: 出个更难的sql题
[同主题阅读] [版面: 数据库] [作者:nmamtf] , 2019年11月07日12:00:44
nmamtf
进入未名形象秀
我的博客
[上篇] [下篇] [同主题上篇] [同主题下篇]

发信人: nmamtf (nmamtf), 信区: Database
标  题: Re: 出个更难的sql题
发信站: BBS 未名空间站 (Thu Nov  7 12:00:44 2019, 美东)

This one separated product value.

You can keep working on it. I don't have much time to complete all of them.

SELECT PRODUCT,
       SEQ,
       P1,
       P2,
       P1_FLAG,
       P2_FLAG,
       PRE_ROW_P1,
       PRE_ROW_P2,
       PRE_ROW_P1_FLAG,
       PRE_ROW_P2_FLAG,
       PRODUCT_FLAG,
      
       DECODE(PRODUCT_FLAG, 1, P1, DECODE (P1_FLAG,1, P1,
           DECODE (PRE_ROW_P1_FLAG,
                   1, PRE_ROW_P1,
                   LAG (PRE_ROW_P1) OVER (ORDER BY PRODUCT, SEQ)))) AS NEW_
P1
  FROM (  SELECT PRODUCT,
                 SEQ,
                 P1,
                 P2,
                 DECODE (P1,  NULL, -1,  0, -1,  1) AS P1_FLAG,            
  
                 DECODE (P2,  NULL, -1,  0, -1,  1)AS P2_FLAG,             
 
                 LAG (P1) OVER (ORDER BY PRODUCT, SEQ) AS PRE_ROW_P1,
                 LAG (P2) OVER (ORDER BY PRODUCT, SEQ) AS PRE_ROW_P2,
                 DECODE (LAG (P1) OVER (ORDER BY PRODUCT, SEQ), 0, -1, 1) AS
PRE_ROW_P1_FLAG,
                 DECODE (LAG (P2) OVER (ORDER BY PRODUCT, SEQ), 0, -1, 1) AS
PRE_ROW_P2_FLAG,
                 DECODE (LAG (PRODUCT) OVER (ORDER BY PRODUCT, SEQ), PRODUCT
, 0, 1) AS PRODUCT_FLAG
            FROM THEMATRIXDATA
        ORDER BY PRODUCT, SEQ);
--
※ 来源:·WWW 未名空间站 网址:mitbbs.com 移动:在应用商店搜索未名空间·[FROM: 152.]

[上篇] [下篇] [同主题上篇] [同主题下篇]
[转寄] [转贴] [回信给作者] [修改文章] [删除文章] [同主题阅读] [从此处展开] [返回版面] [快速返回] [收藏] [举报]
 
回复文章
标题:
内 容:

未名交友
将您的链接放在这儿

友情链接


 

Site Map - Contact Us - Terms and Conditions - Privacy Policy

版权所有,未名空间(mitbbs.com),since 1996