gpt4 book ai didi

jquery - 从多个 MYSQL 表中选择嵌套数据

转载 作者:行者123 更新时间:2023-11-30 00:11:22 24 4
gpt4 key购买 nike

我必须从多个表中选择嵌套数据。

我的表格包括 betting_sport、betting_groups、betting_leagues 和 betting_matches。

每项运动都有很多团体,团体有很多联赛,联赛有很多比赛。

This is screenshot for my tables

我想为 sports->groups->leagues 选择嵌套树,其中仅包含 status=1 的比赛

我尝试了这个选择,但它不起作用:

            select
betting_sport.id as s_id,
betting_sport.title as s_title,
betting_group.id as g_id,
betting_group.title as g_title,
betting_league.id as l_id,
betting_league.title as l_title
from
betting_sport
left join
betting_group
on
betting_group.betting_sport_id = betting_sport.id
left join
betting_league
on
betting_league.betting_group_id = betting_group.id
WHERE
betting_sport.id
IN
(
select betting_sport_id from group where id in (
select
betting_group_id
from
betting_league
where
betting_league.id in (
select betting_league_id from betting_match where status=1
)
)
)

最佳答案

这些表具有良好的线性关系结构,因此不需要双重嵌套查询..

SELECT *
FROM betting_sport
LEFT JOIN betting_group ON betting_sport.id = betting_group.betting_sport_id
LEFT JOIN betting_league ON betting_group.id = betting_league.betting_groupid
LEFT JOIN betting_match ON betting_league.id = betting_match.betting_league_id
WHERE betting_match.status = 1

关于jquery - 从多个 MYSQL 表中选择嵌套数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24017967/

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