求统计SQL 简单的举个例子,表结构是id 和name例如:id ,name 1 aaa 2 bbb 3 ccc 4 aaa 5 ccc 6 ccc ... ....这里要统计出name出现10次以上的有几个,请问该如何写这个统计SQL?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from tabgroup by name having(count(*)) >10 select tn.* from tablename tngroup by tn.name having(count(tn.name)) >10 谢谢,如果我想再进一步,直接算出name数量大于10的总共有多少怎么弄?我这样写不对,select count(select name from tabgroup by name having(count(*)) >10) from tab,该怎么写比较好? select count(name) from tab group by name having(count(*)) >10你那样写,效率不高。。 select count(*) from tabgroup by name having(count(*)) >10 select sum(a.num)from( select tn.name, count(tn.name) num from tablename tn group by tn.name having(count(tn.name)) >10)a; select count(*)from( select name from 表结构 group by name having count(*) >= 10) t; 问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧) (不要高估你的汉语表达能力或者我的汉语理解能力) 建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。 参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html 1. 你的 create table xxx .. 语句 2. 你的 insert into xxx ... 语句 3. 结果是什么样,(并给以简单的算法描述) 4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL) 这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。 恭喜升星了!select count(*) from(select name from tb group by name having(count(1)>10)) x mysql与windows编码问题 数据库行列转换 mysql select into 导出文件的编码格式 insert into A values('a','b'); 这样也能插入数据?? Java链接Mysql的小疑问 求教MySQL的问题,在VB中,插入(insert into)数据时,为什么报这个错 mysql 全文索引 关于非正常格式时间排序问题!感觉有难度 数据库附加问题!在线等! 菜鸟向各位高手们求一段sql代码 谁给个用源码编译安装mysql的过程呢? 自己写的封装MYSQL数据库
group by name having(count(*)) >10
group by tn.name having(count(tn.name)) >10
我这样写不对,select count(select name from tab
group by name having(count(*)) >10) from tab,该怎么写比较好?
group by name having(count(*)) >10
from(
select tn.name, count(tn.name) num from tablename tn
group by tn.name having(count(tn.name)) >10
)a;
from(
select name
from 表结构
group by name
having count(*) >= 10
) t;
(不要高估你的汉语表达能力或者我的汉语理解能力)
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
(
select name from tb group by name having(count(1)>10)
) x