[英]Select all rows with same IDs if one column contains a particular value
我有一张表,大致如下:
Runners Leagues Matches Line InDict
Team 1 LeagueA Match 1 Line 1 'Yes'
Team 2 LeagueA Match 1 Line 1 'Yes'
Team 3 LeagueA Match 1 Line 1 'No'
Team 1 LeagueA Match 4 Line 1 'Yes'
Team 2 LeagueA Match 4 Line 1 'Yes'
Team 1 LeagueA Match 1 Line 2 'Yes'
Team 2 LeagueA Match 1 Line 2 'Yes'
Team 3 LeagueA Match 1 Line 2 'Yes'
Team 1 LeagueB Match 5 Line 8 'No'
Team 2 LeagueB Match 5 Line 8 'Yes'
我想做的是选择“联赛/比赛/线”列相同的所有行,如果其中之一在InDict列中包含“否”值。 因此,在上面的示例中,查询将返回:
Team 1 LeagueA Match 1 Line 1 'Yes'
Team 2 LeagueA Match 1 Line 1 'Yes'
Team 3 LeagueA Match 1 Line 1 'No'
Team 1 LeagueB Match 5 Line 8 'No'
Team 2 LeagueB Match 5 Line 8 'Yes'
我是mysql的新手,因此正在努力为此目的找到正确的查询。
任何帮助是极大的赞赏!
这应该工作:
select * from tableName a where
exists(select * from tableName b where
b.league=a.league and
b.matches=a.matches and
b.line=a.line and
b.inDict="No")
MySQL允许您在in
运算符中使用多个列子查询:
select *
from TableName
where (Leagues,Matches,Line) in (
select Leagues,Matches,Line
from TableName
where InDict='''No'''
)
select * from yourtable
where concat(leagues,Matche,line) in(
select concat(leagues,Matche,line) as v
from yourtable
where InDict = 'No'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.