在SQL

我有这样的数据

Id   code1 code2 code3 code4 code5 code6
1      2     3    4     5     6     7
1      4     5    2     3     7     6
1      7     6    5     2     3     4   
1      5     7    6     4     3     2
1      7     5    6     3     2     4

我需要从5行和6列的这6组代码中识别出不同的代码,并以ID和代码按6行的任意顺序显示它们

输出

ID  Code
1   7
1   6
1   2
1   3
1   5
1   4  

enter image description here

k910427 回答:在SQL

一种方法是使用union

select id,code
from (select id,code1 as code
      from table t
      union
      select id,code2
      from table t
       . . . 
     select id,code6
     from table t
    ) t;
本文链接:https://www.f2er.com/3143262.html

大家都在问