gpt4 book ai didi

mysql - 在其他表中选择条件时获取数据

转载 作者:行者123 更新时间:2023-11-29 22:03:06 25 4
gpt4 key购买 nike

我有 2 个表,现在我想要输出我在 active_season 中选择的赛季的所有比赛。当我尝试下面的查询时,出现错误。有人可以帮助我吗?

SELECT * FROM `matches` 
Where season = active_season.season

错误:#1054 - “where 子句”中存在未知列“active_seasons.season”

table matches
id date season team_a team_b

1 2015-08-23 2015-2016 yellow red
2 2015-04-18 2014-2015 green blue
3 2015-09-04 2015-2016 white brown
4 2014-02-11 2013-2014 pink yellow
5 2015-03-19 2014-2015 red brown
6 2015-11-30 2015-2016 blue pink
7 2015-05-06 2014-2015 green white

table active_season
id season
1 2015-2016

最佳答案

是的,它应该像你所做的那样出错。您需要做的是执行 JOIN 操作,例如

SELECT m.* FROM `matches` m
JOIN active_season ac ON m.season = ac.season;

(或)在您的 FROM 子句中添加表 active_season,例如

SELECT * FROM `matches`, active_season 
Where season = active_season.season

关于mysql - 在其他表中选择条件时获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32423162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com