有两张表,product_intro表和product表,其中product是通过product_intro复制的,字段结构一样,我想给product_intro表中凡是bigclassname=红帽产品 or bigclassname=联想产品 or bigclassname=麒麟产品 or bigclassname=VMware产品 or bigclassname=EMC产品 的行的belong=代理产品,我试了很多次,都没插入成功!有没有遇到过同类问题的,共同探讨下

解决方案 »

  1.   

    insert into product_intro(belong) select belong from product where bigclassname=...-------------------------估计是你的表product_intro里面除了列belong外有非NULL值的列,所以,就不能这样直接插入
      

  2.   

    我是想问下 我这么写sql语句 错在哪儿
    insert into product_intro(belong) select belong from product where bigclassname=红帽产品 or
    bigclassname=联想产品 or bigclassname=麒麟产品 or bigclassname=VMware产品 or bigclassname=EMC产品;
      

  3.   

    因为“insert into product_intro(belong) select belong from ...”这样插入,除了列belong外,其他列的值都填null,而你其他列有限制非null的话,则不能插入,会报错
      

  4.   

    注意下面类似红色的那些点 “ '”
    insert into product_intro(belong) select belong from product where bigclassname='红帽产品' or 
    bigclassname='联想产品' or bigclassname='麒麟产品' or bigclassname='VMware产品' or bigclassname='EMC产品';
      

  5.   

    单独从SQL语句来看, 问题,关键是你的表中其它字段设置,比如是否可以为NULL,是否有
    主键等等
      

  6.   

    我这么做可以吗?
    update product_intro set belong=代理产品 where bigclassname=红帽产品 or
    bigclassname=联想产品 or bigclassname=麒麟产品 or bigclassname=VMware产品 or bigclassname=EMC产品;
    主键ID not null以外,其他字段都可以为空! 我要做的凡是 bigclassname=上述5种产品的,belong都插入“代理产品”
      

  7.   

    如果你的表 product_intro 中已经有这些记录了,则你可以用8#你的语句做 update如果你的表中没有,则需要用 6#楼的 insert
      

  8.   

    你要确定是插入还是UPDATE,即product_intro中是否存在相关记录。
    product_intro表中ID是否是自增字段
      

  9.   


    表已有记录的话,则可以这样update就可以了,你上面的语法有误,如下:update product_intro set belong='代理产品' where bigclassname='红帽产品' or
    bigclassname='联想产品' or bigclassname='麒麟产品' or bigclassname='VMware产品' or bigclassname='EMC产品';