如果有两行数据,如下:
col1 col2
-----------------------
A B
A C
如何通过SQL能显示能
col1 col2
------------------------
A B
C
也就是说重复的列第二行不再显示。
实现这个功能的sql:
with tab as (select 'A' id,'B' name from dual union all select 'A','C' from dual)
select decode(rn,1,id,null),name from (
select id,name ,row_number()over(partition by id order by name) rn from tab
)
查出来的记录为
111 aaa 代理
111 aaa 其他
现在要显示成:
111 aaa 代理
其他
实现的sql: with tab as(select 111 id, 'aaa' name, '代理' type from dual union all
select 111, 'aaa', '其他' from dual)
select decode(rn,1,id,null),decode(rn,1,name,null),type from (
select id,name ,type ,row_number()over(partition by id,name order by type) rn from tab);
col1 col2
-----------------------
A B
A C
如何通过SQL能显示能
col1 col2
------------------------
A B
C
也就是说重复的列第二行不再显示。
实现这个功能的sql:
with tab as (select 'A' id,'B' name from dual union all select 'A','C' from dual)
select decode(rn,1,id,null),name from (
select id,name ,row_number()over(partition by id order by name) rn from tab
)
查出来的记录为
111 aaa 代理
111 aaa 其他
现在要显示成:
111 aaa 代理
其他
实现的sql: with tab as(select 111 id, 'aaa' name, '代理' type from dual union all
select 111, 'aaa', '其他' from dual)
select decode(rn,1,id,null),decode(rn,1,name,null),type from (
select id,name ,type ,row_number()over(partition by id,name order by type) rn from tab);