在线等,求救“列转行问题”
列转行问题
sfzh a1 a2 a3 a4 a5 a6 a7
--------------------
001 求救1 求救2 求救3 求救4 求救5 求救6 求救7
002 救我1 救我2 救我3 救我4 救我5 救我6 救我7
...
999 快来1 快来2 快来3 快来4 快来5 快来6 快来7
修改为:
sfzh ID a
------------------------
001 100 求救1
001 200 求救2
001 300 求救3
001 400 求救4
001 500 求救5
001 600 求救6
001 700 求救7
002 100 救我1
002 200 救我2
002 300 救我3
002 400 救我4
002 500 救我5
002 600 救我6
002 700 救我7
...
999 100 快来1
999 200 快来2
999 300 快来3
999 400 快来4
999 500 快来5
999 600 快来6
999 700 快来7
说明: 转换为行时,a1...a7 分别用ID号:100...700 ,相应列中的内容也进行对应。
[解决办法]
select sfzh,100 as ID,a1 from t union all
select sfzh,200 as ID,a2 from t union all
select sfzh,300 as ID,a2 from t union all
select sfzh,400 as ID,a4 from t union all
select sfzh,500 as ID,a5 from t union all
select sfzh,600 as ID,a6 from t union all
select sfzh,700 as ID,a7 from t order by sfzh,ID
[解决办法]
select * from (
select sfzh,100 as ID,a1 from t union all
select sfzh,200 as ID,a2 from t union all
select sfzh,300 as ID,a2 from t union all
select sfzh,400 as ID,a4 from t union all
select sfzh,500 as ID,a5 from t union all
select sfzh,600 as ID,a6 from t union all
select sfzh,700 as ID,a7 from t) a
[解决办法]
楼上正解.我下面是在你的要新一个表情况
select * into yournewtable from (
select sfzh,100 as ID,a1 from t union all
select sfzh,200 as ID,a2 from t union all
select sfzh,300 as ID,a2 from t union all
select sfzh,400 as ID,a4 from t union all
select sfzh,500 as ID,a5 from t union all
select sfzh,600 as ID,a6 from t union all
select sfzh,700 as ID,a7 from t order by sfzh,ID)