表格布局
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)
任何正确的帮助都会很好
最佳答案
三
select min (id), inactive, name, count(*) from tabke where inactive = 'f' group by inactive, name
日期:
select b.minid, a.inactive, a.name, a.cnt from
(select inactive, name, count(*) cnt from table where inactive = 'f' group by inactive, name) a,
(select inactive, name, min(id) minid from table where inactive = 'f' group by inactive, name) b
where a.inactive = b.inactive and a.name = b.name
关于sql - 可以获得我想要的记录集,寻求建议,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6831164/