引用: http://blog.sina.com.cn/s/blog_6c9d65a10101bkgk.htmlhttp://www.jb51.net/article/39302.htm 1.使用distinct去重(适合查询整张表的总数)有多个学校+教师投稿,需要统计出作者的总数 select count(author) as total from files 每个作者都投稿很多,这里有重复的记录. select distinct author from files; 有可能两个学校的教师姓名
1.distinct select count(distinct CName) from teble select count(CName) from (select distinct CName from Course) as temp SELECT DISTINCT text_zhcn FROM dms_menuconfig -- 去重查询表中数据 select DISTINCT(user_id) from user_info where children_merchant_id='kuai
一.去重 1.查询出重复的记录 CREATE TABLE push_log_full_2013_10_30_tmp SELECT * FROM `push_log_full` WHERE time BETWEEN FROM_DAYS(TO_DAYS(NOW()) - 1) AND FROM_DAYS(TO_DAYS(NOW())) AND (imsi, andriodid, time) IN ( SELECT imsi, andriodid, time FROM `push_log_full`
参考资料:http://blog.csdn.net/guocuifang655/article/details/3993612 方法一: 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所有值.其原因是 distinct只能返回它的目标字段,而无法返回其它字段 下面先来看看例子: table id name 1 a 2 b
delete from 表名 where id not in (select d.id from (SELECT id FROM 表名 GROUP BY c1,c2,c3,c4)as d) #去重复,把url重复,且区为空的中去掉.select * from TABLE where url in (select u.url from (select * from TABLE where id not in (select d.id from (SELECT id FROM TABLE GROUP
1.distinct一般用于获取不重复字段的条数 使用原则: 1)distinct必须放在要查询字段的开头,不能放在查询字段的中间或者后面 select distinct name from user; 获取不重名的name 记录 select id, distinct name from user; 这种写法是错误的,distinct只能写在所有查询字段的前面 2)distinct 对后面所有的字段均起作用,即去重是查询的所有字段完全重复的数据,而不是只对 distinct后面连接的单个字段重
select a.id,a.ssmz,(select count(ssmz) from shop_tourist_key b where b.ssmz=a.ssmz) as count from shop_tourist_key a WHERE a.ssmz is not null group by a.ssmz LIMIT 0,3; select a.id,a.ssmz,(select count(ssmz) from shop_tourist_key b where
项目是基于:thinkcmf的,新的需求是对各栏目的文章数量进行统计 SQl很简单,先根据分类ID进行分组,然后再通过CASE WHEN 再统计不同文章状态数量 ) as count , =已审核 , =未审核 , =审核未通过 FROM term_relationships r join terms t on r.term_id= t.term_id join posts p on p.id = r.object_id group by t.term_id #以分类ID分组 生成的效果: