多了“一只猩猩”,低调散分,顺便求个SQL语句,以免此帖变成纯粹散分帖。表 mytable(主键id为自增长字段)No type
1  1
1  2
2  1
2  2
我要给部分No插入一条type为3的记录,No的条件不用考虑,帮我考虑前面怎么写
Insert into mytable(no,type) select no,'3' from mytable where no in (...)
这样写应该不对,帮我改改。。

解决方案 »

  1.   

    insert into mytable(no, type) values('1','3);
      

  2.   

    是要修改还是插入?
    要这样么?update type = '3'
    from mytable 
    where no in(...)
      

  3.   

    insert into mytable(no, type) values('任意值','3);
      

  4.   

    insert into mytable(no, type) values('...','3);这样应该可以吧,呵呵
      

  5.   


    INSERT INTO myTable(No,type)
    SELECT DISTINCT No,'3'
    FROM myTable
    WHERE No IN (1,2,3,4...)
      

  6.   

    Insert into mytable(no,type) select no,'3' from mytable where no in (3,4,5) 
    从语法上说他是没有问题的,你的不对指的是什么不对?
      

  7.   

    insert into mytable select no, '3' from mytable where ...
      

  8.   

    Insert into mytable(no,type) select no,'3' from mytable where no in (...) 
    可以改为
    Insert into mytable(no,type) select no,'3' from mytable A where A.no in (...) 这样应该可以的吧
    (...)换为
    (select no from mytable B where ...)你要的no就好了
    后面的mytable换成别名
    不然可能会混淆如果少
    就直接用值好了insert into mytable(no, type) values('...','3); 
      

  9.   

    感觉这个答案比较符合插入部分No插入一条type为3的记录
    Insert into mytable(no,type) select  DISTINCT  top 1 no,'3' from mytable where no in (1,2) 
      

  10.   

    No type 
    1  1 
    1  2 
    2  1 
    2  2 自动增长的列 怎么还有 1,1 这样相同的值呢? 
      

  11.   

    你看错了,是ID自动增长,不是no
      

  12.   

    insert into mytable(no, type) values('任意值','3);
      

  13.   

    insert into mytable select no, '3' from mytable where ...
     接分~~ 楼下跟上!
    SQL 语句 
      

  14.   


    Insert into mytable(no,type) select  DISTINCT  top 1 no,'3' from mytable where no in (1,2) 
      

  15.   


    INSERT INTO mytable VALUES ('***','3')谁帮我看看这个。
    http://topic.csdn.net/u/20081205/10/7b6d25fd-0cc9-4c8c-a033-c121a32e36c8.html
      

  16.   

    insert into mytable(no, type) values(1,3);接分
      

  17.   

    insert into mytable select no, '3' from mytable where 1=1
      

  18.   

    个人认为:insert into mytable(no,type) values('...','3');
    这样吧
      

  19.   

    No   type 
    1    1 
    1    2 
    2    1 
    2    2 
    任意  1
    任意  2
    任意  3
    达到这个效果吧!!
      

  20.   

    insert into mytable select no, '3' from mytable where no in(1,2,3)
      

  21.   

    应该有 values 这个关键字吧?
    INSERT语句,可以没有value么?
    学习一下
      

  22.   

    路过..
    直接insert in mytable( no ,type )value('任意你想输入的','3') 
    这样不行吗?
      

  23.   

    我要给部分No插入一条type为3的记录,No的条件不用考虑,帮我考虑前面怎么写 //这句话好象不太好理解啊哦!
      

  24.   

    insert in mytable( no ,type )value('3,'3') 
    楼主还是把问题描述清楚吧
      

  25.   

    因为ID是自动编号,所以lz这样插入需要显示的插入数据,不知道除了No、type、ID还有其他的字段没有,要有可以都加上呀
      

  26.   

    Insert into mytable(no,type) 
         select no,'3' as type from mytable where no in (...)
      

  27.   


    晕啊。。强烈建议CSDN提供二次结帖功能。。呵呵