读书人

加急 ~sql 小疑点(!) NEW 不是很难

发布时间: 2012-01-29 21:39:32 作者: rapoo

加急: ~~~sql 小问题(在线等!) NEW 不是很难!!!
table1

字段: id username userpass type

101 sun sun yy
102 sun sun yy

104 max sun yy

105 po po uu
106 po po uu

109 789 po uu
table2
字段: pID id connent

a01 101 北京
a02 101 上海
a03 101 河北
a04 102 厦门
a05 104 广东
a06 105 瑞典
a07 106 f1
a08 109 合肥
如何将内容重复(id不考虑)的列合为一列,同时添加新的列newID, 以便以后查出合并后的字段。
实现后的效果:
table1
字段: id username userpass type newID

101 sun sun yy 1001
105 po po uu 1002
table2:
pID id connent newID


a01 101 北京 1001
a02 101 上海 1001
a03 101 河北 1001
a04 102 厦门 1001

a05 104 广东

a06 105 瑞典 1002
a07 106 f1 1002
a08 109 合肥


[解决办法]
select distinct(id),username,userpass,type into #B from A;
alter table #B add [newId] int IDENTITY (1001, 1) NOT NULL
select * from #B

读书人网 >C#

热点推荐