T-SQL:检查表列仅具有负值
我有这张表:
Col1 | Col2 |
---|---|
1 | 2 |
1 | 1 |
2 | -2 |
3 | 1 |
3 | -1 |
我只想拥有只有Col2的独特Col1的结果,而Col2都是负的。
这意味着我只想看到col1 = 2
如何做?
I have this table:
col1 | col2 |
---|---|
1 | 2 |
1 | 1 |
2 | -2 |
3 | 1 |
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从桌子中仅选择COL1,其中Col2的最大值小于Col1后少于0。
示例: http://sqlfiddle.com/#!9/25/08ed9b/25/0 < /a>
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