请问图片中的需求能否实现?

leon51 2018-11-12 05:59:56
在下表中,我想找出"card"之间只有一个“filler”的 Part number,
下面的结果应该返回PartB,请问能否实现?SQL应该怎么写?谢谢!

...全文
279 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
nayi_224 2018-11-27
  • 打赏
  • 举报
回复
引用 15 楼 guozf136248 的回复:
[quote=引用 12 楼 nayi_224 的回复:] [quote=引用 11 楼 leon51 的回复:] [quote=引用 6 楼 nayi_224 的回复:]
这回应该是没歧义了,不过还是建议举出包含所有情况的例子,而不是用语言描述 “找出包含一个或多个不连续"filler"的part”跟“找出"card"之间只有一个“filler”的 Part number”所表达的意思完全不同
with tab1 as(
select 'parta' pn, 'card' st, 1 ord from dual union all
select 'parta' pn, 'filler' structure, 2 ord from dual union all
select 'parta' pn, 'filler' structure, 3 ord from dual union all
select 'parta' pn, 'card' structure, 4 ord from dual union all
select 'parta' pn, 'filler' structure, 5 ord from dual union all
select 'parta' pn, 'filler' structure, 6 ord from dual union all
select 'parta' pn, 'card' structure, 7 ord from dual union all
select 'partb' pn, 'card' structure, 1 ord from dual union all
select 'partb' pn, 'filler' structure, 2 ord from dual union all
select 'partb' pn, 'card' structure, 3 ord from dual
)
,tab2 as (
select lead(t1.st) over(partition by t1.pn order by t1.ord) le,
       lag(t1.st) over(partition by t1.pn order by t1.ord) lg,
       t1.pn,
       t1.st
  from tab1 t1
)
select distinct t1.pn 
  from tab2 t1
 where t1.st = 'filler'
   and t1.st != nvl(t1.le, '1')
   and t1.st != nvl(t1.lg, '1')
;
[/quote] 修改如下:
with tab1 as(
select 'parta' pn, 'card' st, 1 ord from dual union all
select 'parta' pn, 'filler' structure, 2 ord from dual union all
select 'parta' pn, 'filler' structure, 3 ord from dual union all
select 'parta' pn, 'card' structure, 4 ord from dual union all
select 'parta' pn, 'filler' structure, 5 ord from dual union all
select 'parta' pn, 'filler' structure, 6 ord from dual union all
select 'parta' pn, 'card' structure, 7 ord from dual union all
select 'partb' pn, 'card' structure, 1 ord from dual union all
select 'partb' pn, 'filler' structure, 2 ord from dual union all
select 'partb' pn, 'card' structure, 3 ord from dual
),
tb11 as(
select t.*,rownum  rm from tab1
)
,tab2 as (
select
     t1.pn,
      lead(t1.st) over( order by t1.rm) le,
       lag(t1.st) over( order by t1.rm) lg,
       t1.st,
       t1.ord
  from tb11 t1
)
select *
  from tab2 t1
 where t1.st = 'filler'
   and t1.st != nvl(t1.le, '1')
   and t1.st != nvl(t1.lg, '1')
;
[/quote] 这种rownum的用法,真实掩耳盗铃。而且关键的partition还让你给删了。数据稍微改一下你就查不出来了。
with tab1 as(
select 'parta' pn, 'filler' st, 1 ord from dual union all
select 'parta' pn, 'filler' structure, 2 ord from dual union all
select 'partb' pn, 'filler' structure, 2 ord from dual union all
select 'parta' pn, 'filler' structure, 3 ord from dual union all
select 'parta' pn, 'filler' structure, 4 ord from dual union all
select 'parta' pn, 'filler' structure, 5 ord from dual union all
select 'parta' pn, 'filler' structure, 6 ord from dual union all
select 'parta' pn, 'filler' structure, 7 ord from dual union all
select 'partb' pn, 'card' structure, 1 ord from dual union all
select 'partb' pn, 'card' structure, 3 ord from dual
),
tb11 as(
select t.*,rownum  rm from tab1 t
)
,tab2 as (
select
     t1.pn,
      lead(t1.st) over( order by t1.rm) le,
       lag(t1.st) over( order by t1.rm) lg,
       t1.st,
       t1.ord
  from tb11 t1
)
select *
  from tab2 t1
 where t1.st = 'filler'
   and t1.st != nvl(t1.le, '1')
   and t1.st != nvl(t1.lg, '1')
;
丨大浣熊丨 2018-11-27
  • 打赏
  • 举报
回复
我是oracle中测试的sql:
select pn from (
select tablename.*,rownum num from tablename
) a where (a.num+1) in (select num from (select tablename.*,rownum num from tablename) where structure='card')
and (a.num-1) in (select num from (select tablename.*,rownum num from tablename) where structure='card')
and a.num in (select num from (select tablename.*,rownum num from tablename) where structure='filler')
guozf136248 2018-11-26
  • 打赏
  • 举报
回复
引用 12 楼 nayi_224 的回复:
[quote=引用 11 楼 leon51 的回复:]
[quote=引用 6 楼 nayi_224 的回复:]


这回应该是没歧义了,不过还是建议举出包含所有情况的例子,而不是用语言描述
“找出包含一个或多个不连续"filler"的part”跟“找出"card"之间只有一个“filler”的 Part number”所表达的意思完全不同

with tab1 as(
select 'parta' pn, 'card' st, 1 ord from dual union all
select 'parta' pn, 'filler' structure, 2 ord from dual union all
select 'parta' pn, 'filler' structure, 3 ord from dual union all
select 'parta' pn, 'card' structure, 4 ord from dual union all
select 'parta' pn, 'filler' structure, 5 ord from dual union all
select 'parta' pn, 'filler' structure, 6 ord from dual union all
select 'parta' pn, 'card' structure, 7 ord from dual union all
select 'partb' pn, 'card' structure, 1 ord from dual union all
select 'partb' pn, 'filler' structure, 2 ord from dual union all
select 'partb' pn, 'card' structure, 3 ord from dual
)
,tab2 as (
select lead(t1.st) over(partition by t1.pn order by t1.ord) le,
lag(t1.st) over(partition by t1.pn order by t1.ord) lg,
t1.pn,
t1.st
from tab1 t1
)
select distinct t1.pn
from tab2 t1
where t1.st = 'filler'
and t1.st != nvl(t1.le, '1')
and t1.st != nvl(t1.lg, '1')
;
[/quote]


修改如下:
with tab1 as(
select 'parta' pn, 'card' st, 1 ord from dual union all
select 'parta' pn, 'filler' structure, 2 ord from dual union all
select 'parta' pn, 'filler' structure, 3 ord from dual union all
select 'parta' pn, 'card' structure, 4 ord from dual union all
select 'parta' pn, 'filler' structure, 5 ord from dual union all
select 'parta' pn, 'filler' structure, 6 ord from dual union all
select 'parta' pn, 'card' structure, 7 ord from dual union all
select 'partb' pn, 'card' structure, 1 ord from dual union all
select 'partb' pn, 'filler' structure, 2 ord from dual union all
select 'partb' pn, 'card' structure, 3 ord from dual
),
tb11 as(
select t.*,rownum rm from tab1
)
,tab2 as (
select
t1.pn,
lead(t1.st) over( order by t1.rm) le,
lag(t1.st) over( order by t1.rm) lg,
t1.st,
t1.ord
from tb11 t1
)
select *
from tab2 t1
where t1.st = 'filler'
and t1.st != nvl(t1.le, '1')
and t1.st != nvl(t1.lg, '1')
;
wildwolv 2018-11-20
  • 打赏
  • 举报
回复
最后的sql应该这样的: select distinct pn from (select pn,st,ord,rownum as XH from tab1 where st = 'f' and XH in (select zrs from tab2,(select a.XH as xh_a,b.XH as xh_b,a.XH-b.XH as CE from ( select XH,rownum as xh_1 from (select pn,st,ord,rownum as XH from tab1 where st = 'a'))a left join (select XH,rownum as xh_2 from (select pn,st,ord,rownum as XH from tab1 where st = 'a')) b on a.xh_1 = b.xh_2+1 where a.XH-b.XH = '2' ) as c where tab2.zrs>c.xh_a and tab2.zrs<xh_b))
wildwolv 2018-11-20
  • 打赏
  • 举报
回复
思路是这样的,应该没问题,你自己再去测试一下 with tab1 as ( select 'a' pn, 'f' st, 1 ord from dual union all select 'a' pn, 'a' st, 2 ord from dual union all select 'a' pn, 'a' st, 3 ord from dual union all select 'a' pn, 'f' st, 4 ord from dual union all select 'b' pn, 'f' st, 1 ord from dual union all select 'b' pn, 'a' st, 2 ord from dual union all select 'b' pn, 'f' st, 3 ord from dual ) , tab2 as ( select 1 ZRS from dual union all select 2 ZRS from dual union all select 3 ZRS from dual union all select 4 ZRS from dual union all select 6 ZRS from dual union all select 7 ZRS from dual union all ) select pn,st,ord,rownum as XH from tab1 where st = 'f' and XH in (select zrs from tab2,(select a.XH as xh_a,b.XH as xh_b,a.XH-b.XH as CE from ( select XH,rownum as xh_1 from (select pn,st,ord,rownum as XH from tab1 where st = 'a'))a left join (select XH,rownum as xh_2 from (select pn,st,ord,rownum as XH from tab1 where st = 'a')) b on a.xh_1 = b.xh_2+1 where a.XH-b.XH = '2' ) as c where tab2.zrs>c.xh_a and tab2.zrs<xh_b)
leon51 2018-11-13
  • 打赏
  • 举报
回复
引用 6 楼 nayi_224 的回复:
with tab1 as (
select 'a' pn, 'f' st, 1 ord from dual union all
select 'a' pn, 'a' st, 2 ord from dual union all
select 'a' pn, 'a' st, 3 ord from dual union all
select 'a' pn, 'f' st, 4 ord from dual union all
select 'b' pn, 'f' st, 1 ord from dual union all
select 'b' pn, 'a' st, 2 ord from dual union all
select 'b' pn, 'f' st, 3 ord from dual 
)
, tab2 as (
select decode(t1.st, 'f', 1, 
decode(lead(t1.st) over(partition by t1.pn order by ord), lag(t1.st) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
t1.pn, t1.st
  from tab1 t1
  )
  select t1.pn from tab2 t1
  where t1.st = 'a'
  group by t1.pn
  having sum(aaa) = 0
  ;
非常感谢你的回复,如果我换个说法,如何找出包含一个或多个不连续"filler"的part?这样会不会方便一点?
leon51 2018-11-13
  • 打赏
  • 举报
回复
引用 9 楼 nayi_224 的回复:
[quote=引用 8 楼 weixin_43566217 的回复:] [quote=引用 6 楼 nayi_224 的回复:]
with tab1 as (
select 'a' pn, 'f' st, 1 ord from dual union all
select 'a' pn, 'a' st, 2 ord from dual union all
select 'a' pn, 'a' st, 3 ord from dual union all
select 'a' pn, 'f' st, 4 ord from dual union all
select 'b' pn, 'f' st, 1 ord from dual union all
select 'b' pn, 'a' st, 2 ord from dual union all
select 'b' pn, 'f' st, 3 ord from dual 
)
, tab2 as (
select decode(t1.st, 'f', 1, 
decode(lead(t1.st) over(partition by t1.pn order by ord), lag(t1.st) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
t1.pn, t1.st
  from tab1 t1
  )
  select t1.pn from tab2 t1
  where t1.st = 'a'
  group by t1.pn
  having sum(aaa) = 0
  ;
我改了一下,主要思想还是这位大哥的,麻烦各位看看对不对 WITH TAB1 AS ( SELECT 'PARTA' PN, 'CARD' STRUCTURE, 1 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 2 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 3 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'CARD' STRUCTURE, 4 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 5 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 6 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'CARD' STRUCTURE, 7 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'CARD' STRUCTURE, 1 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'FILLER' STRUCTURE, 2 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'CARD' STRUCTURE, 3 ORD FROM DUAL ) , TAB2 AS ( SELECT DECODE(T1.STRUCTURE, 'CARD', 1, DECODE(LEAD(T1.STRUCTURE) OVER(PARTITION BY T1.PN ORDER BY ORD), LAG(T1.STRUCTURE) OVER(PARTITION BY T1.PN ORDER BY ORD), 0, 1) ) AAA, PN,STRUCTURE,ORD FROM TAB1 T1 ) SELECT PN,STRUCTURE,ORD FROM TAB2 T1 WHERE AAA=0[/quote] 我都说我写错了... decode会自动对null做判断,会导致这样的语句也能得到结果
with tab1 as (
select 'partb' pn, 'filler' structure, 2 ord from dual 
)
, tab2 as (
select decode(t1.structure, 'card', 1, 
decode(lead(t1.structure) over(partition by t1.pn order by ord), lag(t1.structure) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
pn,structure,ord
  from tab1 t1
  )
select pn,structure,ord from tab2 t1
where aaa=0
应该把decode换成case when。 根据我6楼提出的那种情况的处理方式,最终语句可能还要做修改。[/quote] 完全看不懂,更别说怎么改了
nayi_224 2018-11-13
  • 打赏
  • 举报
回复
引用 8 楼 weixin_43566217 的回复:
[quote=引用 6 楼 nayi_224 的回复:]
with tab1 as (
select 'a' pn, 'f' st, 1 ord from dual union all
select 'a' pn, 'a' st, 2 ord from dual union all
select 'a' pn, 'a' st, 3 ord from dual union all
select 'a' pn, 'f' st, 4 ord from dual union all
select 'b' pn, 'f' st, 1 ord from dual union all
select 'b' pn, 'a' st, 2 ord from dual union all
select 'b' pn, 'f' st, 3 ord from dual 
)
, tab2 as (
select decode(t1.st, 'f', 1, 
decode(lead(t1.st) over(partition by t1.pn order by ord), lag(t1.st) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
t1.pn, t1.st
  from tab1 t1
  )
  select t1.pn from tab2 t1
  where t1.st = 'a'
  group by t1.pn
  having sum(aaa) = 0
  ;
我改了一下,主要思想还是这位大哥的,麻烦各位看看对不对 WITH TAB1 AS ( SELECT 'PARTA' PN, 'CARD' STRUCTURE, 1 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 2 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 3 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'CARD' STRUCTURE, 4 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 5 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 6 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'CARD' STRUCTURE, 7 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'CARD' STRUCTURE, 1 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'FILLER' STRUCTURE, 2 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'CARD' STRUCTURE, 3 ORD FROM DUAL ) , TAB2 AS ( SELECT DECODE(T1.STRUCTURE, 'CARD', 1, DECODE(LEAD(T1.STRUCTURE) OVER(PARTITION BY T1.PN ORDER BY ORD), LAG(T1.STRUCTURE) OVER(PARTITION BY T1.PN ORDER BY ORD), 0, 1) ) AAA, PN,STRUCTURE,ORD FROM TAB1 T1 ) SELECT PN,STRUCTURE,ORD FROM TAB2 T1 WHERE AAA=0[/quote] 我都说我写错了... decode会自动对null做判断,会导致这样的语句也能得到结果
with tab1 as (
select 'partb' pn, 'filler' structure, 2 ord from dual 
)
, tab2 as (
select decode(t1.structure, 'card', 1, 
decode(lead(t1.structure) over(partition by t1.pn order by ord), lag(t1.structure) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
pn,structure,ord
  from tab1 t1
  )
select pn,structure,ord from tab2 t1
where aaa=0
应该把decode换成case when。 根据我6楼提出的那种情况的处理方式,最终语句可能还要做修改。
帅得烦。 2018-11-13
  • 打赏
  • 举报
回复
引用 6 楼 nayi_224 的回复:
with tab1 as (
select 'a' pn, 'f' st, 1 ord from dual union all
select 'a' pn, 'a' st, 2 ord from dual union all
select 'a' pn, 'a' st, 3 ord from dual union all
select 'a' pn, 'f' st, 4 ord from dual union all
select 'b' pn, 'f' st, 1 ord from dual union all
select 'b' pn, 'a' st, 2 ord from dual union all
select 'b' pn, 'f' st, 3 ord from dual 
)
, tab2 as (
select decode(t1.st, 'f', 1, 
decode(lead(t1.st) over(partition by t1.pn order by ord), lag(t1.st) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
t1.pn, t1.st
  from tab1 t1
  )
  select t1.pn from tab2 t1
  where t1.st = 'a'
  group by t1.pn
  having sum(aaa) = 0
  ;
我改了一下,主要思想还是这位大哥的,麻烦各位看看对不对 WITH TAB1 AS ( SELECT 'PARTA' PN, 'CARD' STRUCTURE, 1 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 2 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 3 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'CARD' STRUCTURE, 4 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 5 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'FILLER' STRUCTURE, 6 ORD FROM DUAL UNION ALL SELECT 'PARTA' PN, 'CARD' STRUCTURE, 7 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'CARD' STRUCTURE, 1 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'FILLER' STRUCTURE, 2 ORD FROM DUAL UNION ALL SELECT 'PARTB' PN, 'CARD' STRUCTURE, 3 ORD FROM DUAL ) , TAB2 AS ( SELECT DECODE(T1.STRUCTURE, 'CARD', 1, DECODE(LEAD(T1.STRUCTURE) OVER(PARTITION BY T1.PN ORDER BY ORD), LAG(T1.STRUCTURE) OVER(PARTITION BY T1.PN ORDER BY ORD), 0, 1) ) AAA, PN,STRUCTURE,ORD FROM TAB1 T1 ) SELECT PN,STRUCTURE,ORD FROM TAB2 T1 WHERE AAA=0
nayi_224 2018-11-13
  • 打赏
  • 举报
回复
引用 6 楼 nayi_224 的回复:
with tab1 as (
select 'a' pn, 'f' st, 1 ord from dual union all
select 'a' pn, 'a' st, 2 ord from dual union all
select 'a' pn, 'a' st, 3 ord from dual union all
select 'a' pn, 'f' st, 4 ord from dual union all
select 'b' pn, 'f' st, 1 ord from dual union all
select 'b' pn, 'a' st, 2 ord from dual union all
select 'b' pn, 'f' st, 3 ord from dual 
)
, tab2 as (
select decode(t1.st, 'f', 1, 
decode(lead(t1.st) over(partition by t1.pn order by ord), lag(t1.st) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
t1.pn, t1.st
  from tab1 t1
  )
  select t1.pn from tab2 t1
  where t1.st = 'a'
  group by t1.pn
  having sum(aaa) = 0
  ;
语句还有点问题,这种算不算
select 'a' pn, 'card' st, 1 ord from dual union all
select 'a' pn, 'filter' st, 2 ord from dual union all
select 'a' pn, 'card' st, 3 ord from dual union all
select 'a' pn, 'filter' st, 4 ord from dual union all
select 'a' pn, 'filter' st, 5 ord from dual union all
select 'a' pn, 'card' st, 6 ord from dual 
nayi_224 2018-11-13
  • 打赏
  • 举报
回复
with tab1 as (
select 'a' pn, 'f' st, 1 ord from dual union all
select 'a' pn, 'a' st, 2 ord from dual union all
select 'a' pn, 'a' st, 3 ord from dual union all
select 'a' pn, 'f' st, 4 ord from dual union all
select 'b' pn, 'f' st, 1 ord from dual union all
select 'b' pn, 'a' st, 2 ord from dual union all
select 'b' pn, 'f' st, 3 ord from dual 
)
, tab2 as (
select decode(t1.st, 'f', 1, 
decode(lead(t1.st) over(partition by t1.pn order by ord), lag(t1.st) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
t1.pn, t1.st
  from tab1 t1
  )
  select t1.pn from tab2 t1
  where t1.st = 'a'
  group by t1.pn
  having sum(aaa) = 0
  ;
leon51 2018-11-13
  • 打赏
  • 举报
回复
引用 3 楼 wmxcn2000 的回复:
而是pn中,至少有一对"card"之间只有一个"filler" 这是什么意思,你也画一下。
比如下面这个图片,结果应该是PartB和PartC
nayi_224 2018-11-13
  • 打赏
  • 举报
回复
card
filter
card
filter
filter
card
这种算不算?
卖水果的net 2018-11-13
  • 打赏
  • 举报
回复
而是pn中,至少有一对"card"之间只有一个"filler" 这是什么意思,你也画一下。
leon51 2018-11-13
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:
select pn from t where str = 'filler' group by pn having count(*) = 1
感谢版主的回复,不过不是整个pn中只有一个“filler”,而是pn中,至少有一对"card"之间只有一个"filler",请问应该怎么写?
卖水果的net 2018-11-13
  • 打赏
  • 举报
回复
select pn from t where str = 'filler' group by pn having count(*) = 1
nayi_224 2018-11-13
  • 打赏
  • 举报
回复
引用 11 楼 leon51 的回复:
[quote=引用 6 楼 nayi_224 的回复:]
with tab1 as (
select 'a' pn, 'f' st, 1 ord from dual union all
select 'a' pn, 'a' st, 2 ord from dual union all
select 'a' pn, 'a' st, 3 ord from dual union all
select 'a' pn, 'f' st, 4 ord from dual union all
select 'b' pn, 'f' st, 1 ord from dual union all
select 'b' pn, 'a' st, 2 ord from dual union all
select 'b' pn, 'f' st, 3 ord from dual 
)
, tab2 as (
select decode(t1.st, 'f', 1, 
decode(lead(t1.st) over(partition by t1.pn order by ord), lag(t1.st) over(partition by t1.pn order by ord), 0, 1) 
) aaa,
t1.pn, t1.st
  from tab1 t1
  )
  select t1.pn from tab2 t1
  where t1.st = 'a'
  group by t1.pn
  having sum(aaa) = 0
  ;
非常感谢你的回复,如果我换个说法,如何找出包含一个或多个不连续"filler"的part?这样会不会方便一点? [/quote] 这回应该是没歧义了,不过还是建议举出包含所有情况的例子,而不是用语言描述 “找出包含一个或多个不连续"filler"的part”跟“找出"card"之间只有一个“filler”的 Part number”所表达的意思完全不同
with tab1 as(
select 'parta' pn, 'card' st, 1 ord from dual union all
select 'parta' pn, 'filler' structure, 2 ord from dual union all
select 'parta' pn, 'filler' structure, 3 ord from dual union all
select 'parta' pn, 'card' structure, 4 ord from dual union all
select 'parta' pn, 'filler' structure, 5 ord from dual union all
select 'parta' pn, 'filler' structure, 6 ord from dual union all
select 'parta' pn, 'card' structure, 7 ord from dual union all
select 'partb' pn, 'card' structure, 1 ord from dual union all
select 'partb' pn, 'filler' structure, 2 ord from dual union all
select 'partb' pn, 'card' structure, 3 ord from dual
)
,tab2 as (
select lead(t1.st) over(partition by t1.pn order by t1.ord) le,
       lag(t1.st) over(partition by t1.pn order by t1.ord) lg,
       t1.pn,
       t1.st
  from tab1 t1
)
select distinct t1.pn 
  from tab2 t1
 where t1.st = 'filler'
   and t1.st != nvl(t1.le, '1')
   and t1.st != nvl(t1.lg, '1')
;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧