关于Sql分组的语句

梦里独赏花 2011-10-26 02:39:47
id captureId faceId personId score state

81 36 76 76 760 0

82 36 74 74 600 1

83 36 70 70 590 2

84 39 89 89 690 0

85 39 51 51 600 0

86 39 59 59 590 0

87 40 82 82 610 1

88 40 47 47 600 0

我想得到 根据captureId 分组之后 state全等于0的结果集 请大家帮忙写个SQL语句 谢谢了
...全文
117 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yojinlin 2011-10-27
  • 打赏
  • 举报
回复
路過學習了。
fengyunyin 2011-10-27
  • 打赏
  • 举报
回复
分组的话带 * 不可以吧
congplayer 2011-10-27
  • 打赏
  • 举报
回复
select * from 表名 where state=0 group by captureId
qweeew 2011-10-27
  • 打赏
  • 举报
回复
select * from 表名 where state=0 group by captureId
梦里独赏花 2011-10-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ssp2009 的回复:]
select captureId from tb group by captureId having sum(state)=0
[/Quote]
谢谢高手的方法
梦里独赏花 2011-10-27
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 fengyunyin 的回复:]
分组的话带 * 不可以吧
[/Quote]
可以的 只要你说明按什么条件分组就行 * 代表查询表中所有的字段
suhangkeji 2011-10-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ssp2009 的回复:]
select captureId from tb group by captureId having sum(state)=0
[/Quote]
这个虽然在这里可以,但是其实是有风险的,而且不是很直观的方法。
直接用select * from table where state=0 group by captureID.
用select *才可以保证选出来的是集,直接用state=0就可以保证全部都是state=0,而不会出现其他的组合出来的state=0的情况。谢谢
yeyuhongchch 2011-10-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ssp2009 的回复:]

select captureId from tb group by captureId having sum(state)=0
[/Quote]
好方法~
PaulyJiang 2011-10-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ssp2009 的回复:]
select captureId from tb group by captureId having sum(state)=0
[/Quote]
推荐
xx314250548 2011-10-26
  • 打赏
  • 举报
回复
以上两种方法都可以
暖枫无敌 2011-10-26
  • 打赏
  • 举报
回复

select * from 你的表名 where captureId in
(
select captureId from 你的表名 where state=0 group by captureId
);
快溜 2011-10-26
  • 打赏
  • 举报
回复
select captureId from tb group by captureId having sum(state)=0

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧