子选择列无效问题

发布于 2024-08-22 06:24:52 字数 698 浏览 4 评论 0原文

我在子选择中遇到列名称的 sql 问题,我猜是因为它尚未分配该名称,但我无法弄清楚如何重新排列它。

select Distinct Captains.Name, Captains.Team, (select count(Winners.Name) from (select HomeTeamCaptain As Name from fixture where fixture.HomeTeamCaptain = Captains.Name And fixture.matchResult = fixture.HomeTeam UNION ALL select AwayTeamCaptain As Name from fixture where fixture.AwayTeamCaptain = Captains.Name And fixture.matchResult = fixture.AwayTeam) As Winners) As Winners From (select fixture.HomeTeamCaptain As Name, HomeTeam As Team From fixture UNION ALL select fixture.AwayTeamCaptain As Name, AwayTeam As Team From fixture) As Captains order by Name;

“Captains.Name”是我需要它来运行计数 - 子选择但无法获取其值的问题!

I have a sql issue with column names in a subselect im guessing its because it has yet to be assigned that name but I cannot work out how to rearange it.

select Distinct Captains.Name, Captains.Team, (select count(Winners.Name) from (select HomeTeamCaptain As Name from fixture where fixture.HomeTeamCaptain = Captains.Name And fixture.matchResult = fixture.HomeTeam UNION ALL select AwayTeamCaptain As Name from fixture where fixture.AwayTeamCaptain = Captains.Name And fixture.matchResult = fixture.AwayTeam) As Winners) As Winners From (select fixture.HomeTeamCaptain As Name, HomeTeam As Team From fixture UNION ALL select fixture.AwayTeamCaptain As Name, AwayTeam As Team From fixture) As Captains order by Name;

The "Captains.Name" is the issue I need it to run the Count - Subselect but cannot get hold of its value!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的夜不怕黑 2024-08-29 06:24:52

这对我有用:

select distinct Captains.Name, Captains.Team, 
    (select count(*)  
     from fixture 
     where 
        --I changed this a bit
        (fixture.HomeTeamCaptain = Captains.Name And
         fixture.matchResult = fixture.HomeTeam) 
     OR
        (fixture.AwayTeamCaptain = Captains.Name And 
         fixture.matchResult = fixture.AwayTeam)
    ) As Winners

FROM (select fixture.HomeTeamCaptain As Name, HomeTeam As Team 
     from fixture 
     UNION ALL 
     select fixture.AwayTeamCaptain As Name, AwayTeam As Team 
     from fixture) AS Captains
order by Captains.Name;

您应该考虑创建一个 Captains 表并通过 Id 引用“Home”和“Away”队长。

This works for me:

select distinct Captains.Name, Captains.Team, 
    (select count(*)  
     from fixture 
     where 
        --I changed this a bit
        (fixture.HomeTeamCaptain = Captains.Name And
         fixture.matchResult = fixture.HomeTeam) 
     OR
        (fixture.AwayTeamCaptain = Captains.Name And 
         fixture.matchResult = fixture.AwayTeam)
    ) As Winners

FROM (select fixture.HomeTeamCaptain As Name, HomeTeam As Team 
     from fixture 
     UNION ALL 
     select fixture.AwayTeamCaptain As Name, AwayTeam As Team 
     from fixture) AS Captains
order by Captains.Name;

You should consider creating a Captains table and reference "Home" and "Away" captains by an Id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文