求一个sql语句,多列筛选出不重复数据

wen01071081 2017-04-24 01:39:38
如下列:
人员一 人员二 人员三 人员四
1001 1201 1198
1197 1198 1001
1066 1009 1001 1201
。。。。。。。。。
要筛选出不重复的工号是:
1001
1009
1066
1197
1198
1201

...全文
769 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wen01071081 2017-04-24
  • 打赏
  • 举报
回复
引用 6 楼 wmxcn2000 的回复:
在 10g ,没有别的方法,这是只简单的方法,也是最快的方法了;
嗯 那好咧~ 谢谢了
卖水果的net 2017-04-24
  • 打赏
  • 举报
回复
在 10g ,没有别的方法,这是只简单的方法,也是最快的方法了;
wen01071081 2017-04-24
  • 打赏
  • 举报
回复
引用 4 楼 wmxcn2000 的回复:
-- 10g 不支持 -- 使用 union ,可以去重 select id1 from t union select id2 from t union select id3 from t union select id4 from t
我现在用的就是这样的方法,就想有没有更好一点的
卖水果的net 2017-04-24
  • 打赏
  • 举报
回复
-- 10g 不支持 -- 使用 union ,可以去重 select id1 from t union select id2 from t union select id3 from t union select id4 from t
wen01071081 2017-04-24
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:

-- UNPIVOT 

SQL> 
SQL> create table test(id1 int, id2 int, id3 int, id4 int);
Table created
SQL> insert into test values(100, 200, 400, 600);
1 row inserted
SQL> insert into test values(200, 300, 600, 800);
1 row inserted
SQL> select distinct cc  from test
  2  unpivot(cc for xx in (id1, id2, id3, id4)) x;
                                     CC
---------------------------------------
                                    100
                                    400
                                    600
                                    300
                                    200
                                    800
6 rows selected
SQL> drop table test;
Table dropped

SQL> 
我用的orcale10好像还不支持unpivot
wen01071081 2017-04-24
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:

-- UNPIVOT 

SQL> 
SQL> create table test(id1 int, id2 int, id3 int, id4 int);
Table created
SQL> insert into test values(100, 200, 400, 600);
1 row inserted
SQL> insert into test values(200, 300, 600, 800);
1 row inserted
SQL> select distinct cc  from test
  2  unpivot(cc for xx in (id1, id2, id3, id4)) x;
                                     CC
---------------------------------------
                                    100
                                    400
                                    600
                                    300
                                    200
                                    800
6 rows selected
SQL> drop table test;
Table dropped

SQL> 
这个里面的xx和x是什么意思
卖水果的net 2017-04-24
  • 打赏
  • 举报
回复

-- UNPIVOT 

SQL> 
SQL> create table test(id1 int, id2 int, id3 int, id4 int);
Table created
SQL> insert into test values(100, 200, 400, 600);
1 row inserted
SQL> insert into test values(200, 300, 600, 800);
1 row inserted
SQL> select distinct cc  from test
  2  unpivot(cc for xx in (id1, id2, id3, id4)) x;
                                     CC
---------------------------------------
                                    100
                                    400
                                    600
                                    300
                                    200
                                    800
6 rows selected
SQL> drop table test;
Table dropped

SQL> 

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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