T-SQL:检查表列仅具有负值

发布于 2025-02-14 01:32:27 字数 689 浏览 0 评论 0原文

我有这张表:

Col1Col2
12
11
2-2
31
3-1

我只想拥有只有Col2的独特Col1的结果,而Col2都是负的。

这意味着我只想看到col1 = 2

如何做?

I have this table:

col1col2
12
11
2-2
31
3-1

I only want to have a results of distinct col1 which having only col2 are ALL negative.

Which means I want to have only see col1 = 2

How to do that?

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

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

发布评论

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

评论(1

半衬遮猫 2025-02-21 01:32:27
SELECT col1 from table1 t
group by t.col1
having max(t.col2) < 0

您可以从桌子中仅选择COL1,其中Col2的最大值小于Col1后少于0。

示例: http://sqlfiddle.com/#!9/25/08ed9b/25/0 < /a>

SELECT col1 from table1 t
group by t.col1
having max(t.col2) < 0

you can select just col1 from your table where the max value of col2 is less than 0 after grouping by col1.

Example: http://sqlfiddle.com/#!9/08ed9b/25/0

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