gpt4 book ai didi

mysql - 将大连接查询与重复查询相结合

转载 作者:行者123 更新时间:2023-11-29 05:58:08 24 4
gpt4 key购买 nike

我正在努力组合这两个 sql 查询。

SELECT players.player_id, players.tag, players.game_race,
earnings.tournament, earnings.player, earnings.position,
tournaments.tournament_id, tournaments.region
FROM players
JOIN earnings ON players.player_id = earnings.player
JOIN tournaments ON earnings.tournament = tournaments.tournament_id
where position = 1
ORDER BY players.player_id;

SELECT tournament, earnings.player, prize_money, position 
FROM earnings
join (
SELECT player FROM earnings
where position = 1 group by player having count(player) > 3)
as DupPlayer
on earnings.player=DupPlayer.player
where position = 1;

所以我尝试了一个工会。

(SELECT players.player_id, players.tag, players.game_race,
earnings.tournament, earnings.player, earnings.position,
tournaments.tournament_id, tournaments.region
FROM players
JOIN earnings ON players.player_id = earnings.player
JOIN tournaments ON earnings.tournament = tournaments.tournament_id
where position = 1
ORDER BY players.player_id
)
UNION
(
SELECT tournament, earnings.player, prize_money, position
FROM earnings
join (
SELECT player FROM earnings
where position = 1 group by player having count(player) > 3)
as DupPlayer
on earnings.player=DupPlayer.player
where position = 1
);

然后我收到错误消息“使用的 SELECT 语句具有不同的列数”。我该如何解决这个问题?有没有比 union 更好的方法?我真的不想更改我的选择语句,因为我想查看所有这些列。

最佳答案

像下面这样组合查询:

SELECT players.player_id, players.tag, players.game_race,
earnings.tournament, earnings.player, earnings.position,
tournaments.tournament_id, tournaments.region
FROM players
JOIN earnings ON players.player_id = earnings.player
JOIN (SELECT player FROM earnings
where position = 1 group by player having count(player) > 3)
as DupPlayer on earnings.player=DupPlayer.player
JOIN tournaments ON earnings.tournament = tournaments.tournament_id
where position = 1
ORDER BY players.player_id;

关于mysql - 将大连接查询与重复查询相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47475646/

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