我有一个关于足球(足球)统计数据的数据库。其中一个表是匹配,其中包含以下行:
另一个表格是目标,其中包含以下行:
当home_level为3 且 away_level为1 且(away_score - home_score> 2)时,我想选择所有目标。
如何生成此查询,包括2个表?
答案 0 :(得分:-1)
试试这个:
select *
from matches m,
goal g
where m.id = g.match_id
and g.home_level = 3
and g.away_level = 1
and m.away_score - m.home_score > 2
或
select *
from matches m,
goal g
where m.id = g.match_id
and g.home_level = 3
and g.away_level = 1
and (m.away_score - m.home_score) > 2
或
select *
from matches m
INNER_JOIN goal g ON m.id = g.match_id
and g.home_level = 3
and g.away_level = 1
and (m.away_score - m.home_score) > 2