一张表字段如下
id 主键
productid 外键
teamid 外键
state 想要根据多条记录中的teamid 与state 确定productid
比如:
productid 1
teamid 1
state 0productid 1
teamid 2
state 3这是两条记录,要根据teamid=1 state=0 这条记录与teamid=2 state=3 这条  查出 为1的productid来

解决方案 »

  1.   


    select
    from 
    where ((teamid=1 and state=0) or (teamid=2 and state=3))
      

  2.   

    select *
    from tablename1,tablename2
    where (teamid=1 and state=0) or (teamid=2 and state=3) and tablename1.id=tablename2.productid and tablename2.productid=1
      

  3.   

    or  不行的  也没有productid=1这个条件  这是要查到的结果
      

  4.   


    --搞不懂你要做什么
    --???
    select discinct productid
    from tb 
      

  5.   

    这是一张表?如果是一张表,你只需要一条记录中的teamid和state就可以查到productid了啊。你的意思是不是说通过一对teamid和state找到和它俩拥有相同productid的另外的一对teamid和state呢?或者是说teamid和state对应的productid不唯一,找两对teamid和state共同对应的productid交集?如果是后者,那么应该是:select a.productid from tablename a, tablename b
    where a.teamid = 1
     and a.state = 0
     and b.teamid = 2
     and b.state = 3
     and a.productid = b.productid