有两个表 dutbin   和 testitemdutbin结构:
DID (主键 自增长)
customerlotid
state
hifix
pgm
pgm version
bin
testitem
testitem结构:
did
pgm
pgm_version
testitem_no
testitem_nifo
现在求testitem_info,判别条件:当dutbin的pgm,pgm version和表testitem的pgm,pgm version一一对应相等时,testitem_no的值等于x时,求得testitem_info.现在我的语句是这样的,但是求得结果不对,请问错在哪里?select testitem_info from dutbin,testitem where dutbin.PGM = testitem.PGM and dutbin.\"Pgm version\" = testitem.PGM_VERSION and testitem.testitem_no = '$testitem_num'

解决方案 »

  1.   


    select t.testitem_nifo from testitem t,dutbin d
    where t.testitem_no='x' and t.pgm=d.pgm and t.pgm_version=d.pgm_version 如果要左连select t.testitem_nifo from testitem t,dutbin d
    where t.testitem_no='x' and t.pgm=d.pgm(+) and t.pgm_version=d.pgm_version(+)楼主sql不对是不是两个表关联的字段类型不匹配
      

  2.   

    我想要的结果是:当testitem 的pgm ,pgm_version 等于 dutbin的pgm,pgm version时,则取当testitem等于‘x’的testitem_info的值。
      

  3.   

    1楼的 答案已经很完整了啊,两个字段两种关联,testitem=‘x’过滤,除非还需要有些null什么的数据需要查出,那样的话,加上 or testitem is null
      

  4.   

    用程序理解吧:
    if((testitem.pgm==dutbin.pgm)&&(testitem.pgm_version==dutbin."Pgm version"))
    {
       sql = select testitem_info from testitem where testitem_no = 'x';
       result;
    }
      

  5.   

    1楼这个sql就满足你要求吧
    select t.testitem_nifo from testitem t,dutbin d
    where t.testitem_no='x' and t.pgm=d.pgm and t.pgm_version=d.pgm_version