这个是论坛的表
pw_threads是主贴表
pw_post是回帖表由于某些错误,回帖表中的fid列(板块id)的值是空的,应该是和主贴的fid一样才对。
所以我写了一个语句,但是影响0行,无效。请指教
update pw_posts a,pw_threads b set a.fid=b.fid where a.tid=b.tid and a.fid=0

解决方案 »

  1.   

    update pw_posts a,pw_threads b set a.fid=b.fid where a.tid=b.tid and a.fid is null
      

  2.   


    我说的为空就是fid=0,不是null
      

  3.   

    贴建表及插入记录的SQL,及要求结果出来看看
      

  4.   

    回帖表里面有个字段fid是板块id,主贴表里也有个字段fid,那个表里的fid还是正常的。所以想借由主贴表的fid写到回帖表里的fid就行了。表比较复杂,我捡重点说了
      

  5.   

    tid就是主贴id,如果老大能看懂就好了,不行我就自己想办法了。
      

  6.   


    pw_threads是主贴表
    pw_post是回帖表
    两个 表的FID、TID字段内容
      

  7.   

    pw_threads 可以认为只有2个字段
    tid(主贴id) fid(板块id) pw_posts 可以认为只有2个字段
    tid fid 
    同一个帖子的回帖和主贴的fid肯定应该是一样的,同时tid也一样。
    但是目前pw_posts表中有些记录fid=0,但是tid还是正常的。所以希望通过查找pw_threads表中对应tid的fid来修复pw_posts表
      

  8.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  9.   

    fid,tid都是数字而已,1,3,5,23,这样的
      

  10.   

    试试,你的SQL应该没有问题
    update pw_posts a inner join pw_threads b on a.tid=b.tid 
    set a.fid=b.fid where a.fid=0
      

  11.   

    我用select * from pw_posts where fid=0查看,还是老样子,还是有些回帖fid是0
      

  12.   

    select * from pw_posts a inner join pw_threads b on a.tid=b.tid
    结果如何
      

  13.   

    是不是 a.tid=b.tid  的行数本来就是零呢?你先用楼上的语句测一下,看看是不是没有符合你条件的行。