不在 SQL Server 2005 中

发布于 2024-09-27 00:51:51 字数 246 浏览 2 评论 0原文

我怎么能看到表中没有的东西...我知道我知道...只能看到那里有的东西但是来吧!

所以!!

select * from ORDER where State IN ('MA','PA','GA','NC')       

所以我会得到 MA 和 PA,但我想看看 GA 和 NC...

NOT IN 将返回 NY、NJ、CT 等...我只想看看 ( )

How can I see what is not in the table... I know I know...can only see what is there but come on!!!

So!!

select * from ORDER where State IN ('MA','PA','GA','NC')       

So I will get MA and PA but I want to see GA and NC....

NOT IN will return NY,NJ,CT ect.... I just want to see what is in the ( )

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

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

发布评论

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

评论(4

灯角 2024-10-04 00:51:51

看起来您在 GA 前面缺少一个单引号 '

It looks like you are missing a single quote ' in front of GA.

从来不烧饼 2024-10-04 00:51:51

我对这个问题的理解是:对于给定的状态列表,哪些状态不存在于 Order 表中?

这将向您显示下面列出的四个状态中哪些状态在 <代码>订单表:

select distinct s.State
from
(
    select 'MA' as State
    union all
    select 'PA'
    union all
    select 'GA'
    union all
    select 'NC'
) s
left outer join [Order] o on s.State = o.State
where o.State is null

My understanding of the question is: For a given list of states, which ones do not exist in the Order table?

This will show you what states out of the four listed below have no corresponding records in the Order table:

select distinct s.State
from
(
    select 'MA' as State
    union all
    select 'PA'
    union all
    select 'GA'
    union all
    select 'NC'
) s
left outer join [Order] o on s.State = o.State
where o.State is null
瞄了个咪的 2024-10-04 00:51:51

我将尝试在这里阅读一下字里行间:

;with cteStates as (
    select 'MA' as state
    union all
    select 'PA'
    union all 
    select 'GA'
    union all
    select 'NC'
)
select s.state, count(o.state) as OrderCount
    from cteStates s
        left join [order] o
            on s.state = o.state
    group by s.state

I'm going to try to read between the lines a little here:

;with cteStates as (
    select 'MA' as state
    union all
    select 'PA'
    union all 
    select 'GA'
    union all
    select 'NC'
)
select s.state, count(o.state) as OrderCount
    from cteStates s
        left join [order] o
            on s.state = o.state
    group by s.state
行至春深 2024-10-04 00:51:51

您只是想找出除了这四个州之外还有哪些州吗?如果是这样:

SELECT DISTINCT State FROM dbo.ORDER WHERE State NOT IN ('MA', 'PA', 'GA', 'NC')

Are you just trying to find out which states there are except for those four? If so:

SELECT DISTINCT State FROM dbo.ORDER WHERE State NOT IN ('MA', 'PA', 'GA', 'NC')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文