gpt4 book ai didi

MySQL INNER JOIN 别名

转载 作者:IT老高 更新时间:2023-10-28 23:46:43 24 4
gpt4 key购买 nike

有谁知道我如何在其中进行内部连接和别名值,这样它们就不会相互覆盖?如果您看到我的代码,它可能看起来更清楚:

    SELECT  home, away, g.network, g.date_start 
FROM game g
INNER JOIN team t ON (
(t.importid = g.home) as home
OR
(t.importid = g.away) as away
)
ORDER BY date_start DESC
LIMIT 7

已解决(下面的帮助是我的最终查询)

    SELECT 
home.market AS home_market,
away.market AS away_market,
g.network,
g.date_start

FROM game AS g
INNER JOIN team AS home ON (
home.importid = g.home
)
INNER JOIN team AS away ON (
away.importid = g.away
)

ORDER BY g.date_start DESC
LIMIT 7

最佳答案

您需要参加两次:

SELECT home.*, away.*, g.network, g.date_start 
FROM game AS g
INNER JOIN team AS home
ON home.importid = g.home
INNER JOIN team AS away
ON away.importid = g.away
ORDER BY g.date_start DESC
LIMIT 7

关于MySQL INNER JOIN 别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10724324/

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