After calculating the number of posts for each group using "count(name)," we want to output the results where the count is greater than 5 (count(name)>5). This requires using "having" to set the condition for filtering the results after grouping. The difficulty here lies in understanding the use of "having."
正确答案是:B: select id, count(name) from t1 group by id having count(name)>5;
专业分析:
1. **选项A**: `select id, count(name) from t1 group by id;`
- 这个语句会按照`id`分组,并计算每个`id`对应的`name`的数量。但是,它没有筛选出帖子数量大于5的条件。
2. **选项B**: `select id, count(name) from t1 group by id having count(name)>5;`
- 这个语句不仅按照`id`分组并计算每个`id`对应的`name`的数量,还通过`having`子句筛选出帖子数量大于5的记录。因此,这是正确的答案。
3. **选项C**: `select id, count(name) from t1 group by id having count(name)>5 order by count(name);`
- 这个语句与选项B类似,但多了一个`order by`子句,用于按帖子数量排序。虽然语法正确,但题目只要求筛选出帖子数量大于5的记录,并没有要求排序,因此不是最佳答案。
4. **选项D**: `select id, count(name) from t1 where id > 100 group by id;`
- 这个语句在分组之前增加了一个`where`条件,筛选出`id`大于100的记录。这个条件与题目要求无关,因此不是正确答案。
综上所述,选项B最符合题目要求。