【发布时间】:2011-07-26 13:58:17
【问题描述】:
表格布局
id, inactive (Boolean), name
12500, f, foo
12345, f, foo
12344, f, foo
12343, f, foo
12342, t, foo
12..., t, foo (more records)
12200, f, bar
12005, f, bar
12004, f, bar
12003, f, bar
12002, t, bar
12..., t, bar (more records)
..............(more records with different names)
结果:
- 需要按名称分组
- 只需要非活动 = f
- 需要拳头不活动 = f, id
- 需要计算每个组的记录数,非活动 = f
所以从上面的示例数据中我会得到以下结果集:
id, inactive (Boolean), name, count
12343, f, foo, 157
12003, f, bar, 197
............. (any other names that fall into the above constraints)
对正确方向的任何帮助都会很棒
【问题讨论】:
-
第一个建议:写一条sql语句。然后当它不起作用时,寻求帮助。
-
感谢 Randy 的建议,事实上,我确实写了几个查询,但没有达到我想要的效果。因此我提出了这个问题。我认为让某人查看所需结果而不是我的查询会更容易
标签: sql postgresql group-by