mysql查询不重复数据
2015-10-14 19:24
507 查看
1.查询不重复数据
select *, count(distinct name) from table group by name;
2.查询重复数据
select userid from table where userid in ( select userid from table group by userid having count(userid)>1);
sql:
select *, count(distinct name) from table group by name;
2.查询重复数据
select userid from table where userid in ( select userid from table group by userid having count(userid)>1);
sql:
SELECT sa.id AS said, sa.CREATE_DATE, u.user_name AS '所属人', cus.qq AS 重复的QQ FROM xxx.sale_airticket sa LEFT JOIN xxx.sale_air_customer sac ON sac.SALE_AIRTICKET_ID = sa.id LEFT JOIN xxx.customerr cus ON cus.id = sac.CUSTOMER_ID LEFT JOIN xxx.busers u ON u.user_id = cus.USER_ID WHERE cus.qq IN ( SELECT qq FROM travel.customerr WHERE qq != '' GROUP BY qq HAVING Count(*) > 1 ) GROUP BY sa.id HAVING COUNT(*) = 1 ORDER BY cus.qq
相关文章推荐
- MySQL中的字符集
- MySQL用户权限(Host,User,Password)管理(mysql.user)
- MySQL命令记录1
- 需求:MYSQL表中一个字段用逗号分隔,需要查出来split拆分并依次存入另一个表的一个字段中
- mysql中内存的使用与分配
- 日记 - Mysql数据库的基础知识一
- MySQL索引工作原理
- MYSQL limit,offset 区别
- mysql 查询表同时删除该表中的数据
- 由浅入深探究 MySQL索引结构原理、性能分析与优化
- MySQL日志
- MYSQL使用inner join 进行 查询,删除,修改
- hibernate无法自动创建表的原因整理
- ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘mysql’
- MySQL之——MySQL使用中遇到的有关问题
- 使用mysql中的with rollup得到group by的汇总信息
- Table '.\mysql\proc' is marked as crashed and should be repaired 报错
- mysql中的int smallint 取值范围
- windows上mysql的完全卸载
- MySQL InnoDB存储引擎的内存及其管理