比如一个表TABLE1
张三  A01
李四  A02
张三  A01
李四  A02
王五  A03
要生成这样的表TABLE2
张三 A01
李四 A02
王五 A03
我的原insert语句在sqlserver中通不过
insert into table2 (xm,zgh...) select xm,zgh... from table1 where LF=2002 group by zgh .
zgh为唯一的。

解决方案 »

  1.   

    group離把select中的字段都添上去
      

  2.   

    select xm,zgh... from table1 where LF=2002 group by zgh .
    ------------------上面的语句应该是错的!-----------------------------------------------------------------
    欢迎访问:http://CoolSlob.fykj.com/。目前唯一可以查询CSDN FAQ的站点!
      

  3.   

    我举个例子:TABLE1
    张三   1000   2002 1
    李四   1200   2002 1
    张三   1320   2002 2
    李四   1321   2002 2
    王五   2320   2002 2
    ---------------------------
    要生成:TABLE2
    张三  1000  1320
    李四  1200  1321
    王五        2320
      

  4.   

    要达到这样的效果没那么简单的!结果UDF可能会好做些。-----------------------------------------------------------------
    欢迎访问:http://CoolSlob.fykj.com/。目前唯一可以查询CSDN FAQ的站点!
      

  5.   

    insert into table2 (xm,zgh...) select xm,zgh... from table1 where LF=2002 group by zgh .到底错在哪呢
      

  6.   

    nsert into table2 (xm,zgh...) select xm,zgh... from table1 where LF=2002 可以通过,
    若加上group by zgh 就说group错。
      

  7.   

    insert into table2 (xm,zgh...) select xm,zgh... from table1 where LF=2002 order by zgh将group改为order
      

  8.   

    insert 语句中不能用select 语句吧。
      

  9.   

    select xm,zgh... from table1 where LF=2002
    如果你使用了group by子句,在你select的字段中,除合计字段以处,其它均必须包括到group by 子句中。-----------------------------------------------------------------
    欢迎访问:http://CoolSlob.fykj.com/。目前唯一可以查询CSDN FAQ的站点!