SQL中的所有操作员

发布于 2025-02-12 01:35:58 字数 250 浏览 2 评论 0原文

我有一项任务可以选择所有工人的职位,其中所有工人的工资在400-700美元之间。但是我的查询不起作用,我不知道为什么。

SELECT DISTINCT position
FROM 
    job
WHERE position = ALL   
(SELECT
        position
     FROM 
        job
    WHERE 
        salary BETWEEN 400 and 700);

I have a task to select positions all workers of which get salary between 400-700$. But my query does not work I do not know why.

SELECT DISTINCT position
FROM 
    job
WHERE position = ALL   
(SELECT
        position
     FROM 
        job
    WHERE 
        salary BETWEEN 400 and 700);

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

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

发布评论

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

评论(1

2025-02-19 01:35:58

扭转条件:

select a.* 
  from ( select distinct position from job) a
 where position not in (
         select position
           from job
          where salary < 400 or salary > 700
       )

您可能还想阅读所有操作员的工作方式。您的查询错误地假设所有职位都是相同的(否则所有职位都无法正常工作)。

或者,使用全部两次:

select a.* 
  from (
    select distinct position 
       from job
           ) a
where 400 >=  ALL (
              select salary
                 from job
                where position = a.position
           )
  and 700 <=  ALL (
              select salary
                 from job
                where position = a.position
           )

Reverse the condition:

select a.* 
  from ( select distinct position from job) a
 where position not in (
         select position
           from job
          where salary < 400 or salary > 700
       )

You also might want to read about how ALL operator works like. Your query incorrectly assumes all positions are the same (otherwise ALL will not work).

Alternatively, use ALL twice:

select a.* 
  from (
    select distinct position 
       from job
           ) a
where 400 >=  ALL (
              select salary
                 from job
                where position = a.position
           )
  and 700 <=  ALL (
              select salary
                 from job
                where position = a.position
           )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文