一张表字段如下
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来
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来
select
from
where ((teamid=1 and state=0) or (teamid=2 and state=3))
from tablename1,tablename2
where (teamid=1 and state=0) or (teamid=2 and state=3) and tablename1.id=tablename2.productid and tablename2.productid=1
--搞不懂你要做什么
--???
select discinct productid
from tb
where a.teamid = 1
and a.state = 0
and b.teamid = 2
and b.state = 3
and a.productid = b.productid