首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获取sql表的所有名称?

如何获取sql表的所有名称?
EN

Stack Overflow用户
提问于 2022-05-24 12:22:31
回答 1查看 48关注 0票数 1

我很难弄清楚所有人的名字,也不知道他们是否会打橄榄球。

如果播放,则显示Yes,否则为No。目前我只得到一个人打橄榄球的结果,而不是其他不打橄榄球的人。有谁可以帮我?

当前SQL:

代码语言:javascript
运行
复制
select P1.name, case when S.sport = 'rugby' then 'Yes' else 'No' end as rugby
    from Persons P1, 
         Persons  P2, 
         SportTogether S
    where P1.id = S.personA_id 
      and P2.id = S.personB_id
      and S.sport = 'rugby'
    group by case when S.sport = 'rugby' then 'Yes' else 'No' end;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-24 12:40:27

在我看来,你使用了错误的方法。您想要选择人员,所以从persons表中选择。你想知道一个人是否玩橄榄球,所以在橄榄球桌上找人。查找可以用INEXISTS完成。

代码语言:javascript
运行
复制
select
  name,
  case when exists 
  (
    select null 
    from sporttogether s
    where s.sport = 'rugby'
    and p.id in (s.persona_id, s.personb_id)
  ) then 'Yes' else 'No' end as plays_rugby
from persons p
order by name;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72362824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档