有两个表 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.用程序理解吧:
if((testitem.pgm==dutbin.pgm)&&(testitem.pgm_version==dutbin."Pgm version"))
{
  sql = select testitem_info from testitem where testitem_no = 'x';
  result;
}请问怎么写?

解决方案 »

  1.   

    select B.testitem_info from dutbin AS A inner join testitem AS B on (A.pgm = B.pgm and A.pgm_version = B.pgm_version) where B.testitem_no = X
      

  2.   


    select testitem_info from dutbin d,testitem t where d.pgm = t.pgm and d.pgm_version = t.pgm_version and testitem_no = 'x';
    这样不行么?
      

  3.   

    select te.testitem_nifo from  dutbin du
    left join testitem te on(te.pgm=du.pgm and te.pgm_version=du.pgm_version)where te.testitem_no='x'
      

  4.   

    好像结果都不正确。
    我的意思是能不能先单独判断d.pgm = t.gm && d."Pgm version"=t.gm_version,再进行后续操作?像这样,
    if((testitem.pgm==dutbin.pgm)&&(testitem.pgm_version==dutbin."Pgm version"))
    {
      sql = select testitem_info from testitem where testitem_no = 'x';
      result;
    }
      

  5.   

    测试下来pgm和pgm_version都不相等,但是依然有相等时的结果出现。
      

  6.   


    答案不正确啊。a.pgm!=b.pgm时也有正确结果。
      

  7.   

    用内联吧。
    select te.testitem_nifo from dutbin du,testitem te 
    where te.pgm=du.pgm and te.pgm_version=du.pgm_version and te.testitem_no='x'
      

  8.   

    不对啊。
    select dutbin.PGM,dutbin."Pgm version",testitem.TESTITEM_INFO from dutbin left join testitem on(testitem.PGM = dutbin.PGM and testitem.PGM_VERSION = dutbin."Pgm version")where testitem.TESTITEM_NO = 46;结果:
    O624XF3D    N.30  abcabc
    O624XF3D    N.30  abcabc
    O624XF3D    N.30  abcabc
    O624XF3D    N.30  abcabc但是select dutbin.pgm,dutbin."Pgm version" from dutbin
    的结果却是:
    T534W8U6    N.21这pgm,pgm version两项都不等,但是怎么能得出结果?