现在一个表,有这几个列:
ID NAME GENDER AGE City compus...(还有)
其中ID 和NAME 是起主键作用的列(但没有设置为主键)原来呢,应该是一个ID 和NAME 对应一条数据
但由于以前编程错误
导致一条数据被拆成了互斥的两行
比如
1 wang mail 20    null       null
1 wang null null  shanghai   sh-university现在有没有什么SQL语句(或是其他办法也行)
可以把这样的两条合并起来呢?
(数据库表中这样的2条有N多行呢,所以不可能手动逐条做啦)先谢谢啦

解决方案 »

  1.   

    select ID ,NAME max(GENDER)GENDER, max(AGE)AGE,max(City)City, ....
    into table1 from 表 group by id,nameselect * from table1
      

  2.   

    select id,name,max(GENDER) as GENDER,max(AGE) as age,max(City) as city from t group by id,name
      

  3.   

    假设你的表是table1,第1列就是c1,类推select distinct a.c1,a.c2, isnull(a.c3,b.c3),isnull(a.c4,b.c4),
       isnull(a.c5,b.c5),isnull(a.c6,b.c6)
    from table1 a 
    inner join table1 b
    on a.c1=b.c1 and a.c2=b.c2