b站电脑弹幕怎么关闭闭

mysql SELECT语句去除某个字段的重复信息
阅读:1352次&&&时间: 08:47:37&&
SELECT语句,去除某个字段的重复信息,例如: 表名:table id uid username message dateline 1 6  a    111    (时间戳) 2 6  a    222     3 8  b    444     4 9  c    555     执行语句(去除username字段重复信息并按时间排序): SELECT * FROM table a INNER JOIN ( SELECT max( dateline ) AS dateline FROM table GROUP BY uid ) b ON a.dateline = b.dateline GROUP BY id ORDER BY a.dateline DESC 结果: id uid username message dateline 1 6  a    111    (时间戳) 3 8  b    444     4 9  c    555     此语句用于显示最新记录信息,在一个区域内不允许某个信息(例如:用户)同时出现多次(一次以上)。 后记:效率问题 开始用了个这语句: select * from table where dateline IN ( select max(dateline) from table GROUP BY uid ) ORDER BY dateline DESC IN:当处理数据量比较大的时候,就没效率可言了,所以优化成内联,计算下快了6倍多。。。 继续条效率就加索引了~~
[商业源码]&
[商业源码]&
[商业源码]&
[商业源码]&
[商业源码]&
[商业源码]&
[商业源码]&
[商业源码]&
[商业源码]&
[商业源码]&
Copyright &
All Rights Reserved如何用sql语句查询和删除表中重复数据
- Mysql - 网页特效代码
如何用sql语句查询和删除表中重复数据
如何用sql语句查询和删除表中重复数据
分类:&&&时间: 09:54:58&&&点击:
如何用sql语句查询和删除表中重复数据
1、查询表中重复数据(单字段)
Select * From 表 Where 字段1 In (Select 字段1 From 表 Group By 字段1 Having Count(字段1) & 1)
2、删除表中多余的重复记录,只留有rowid最小的记录(单字段)
Delete From 表
Where 字段1 In (Select 字段1 From 表 Group By 字段1 Having Count(字段1) & 1) And
&& Rowid Not In (Select Min(Rowid) From 表 Group By 字段1 Having Count(字段1) & 1)
3、查找表中多余的重复记录(多个字段)
Select * From 表 a Where (a.字段1, a.字段2) In (Select 字段1, 字段2 From 表 Group By 字段1, 字段2 Having Count(*) & 1)
4、删除表中多余的重复记录,只留有rowid最小的记录(多个字段)
Delete From 表 a
Where (a.字段1, a.字段2) In (Select 字段1, 字段2 From 表 Group By 字段1, 字段2 Having Count(*) & 1) And
&& Rowid Not In (Select Min(Rowid) From 表 Group By 字段1, 字段2 Having Count(*) & 1)
5.删除多于的重复记录(单个字段,多个字段)
delete from table where id not in ( select min(id) from table group by name)
delete from table where id not in ( select min(id) from table group by 字段1,字段2)
6.删除多余的重复记录(单个字段,多个字段)
delete from table where id in ( select max(id) from table group by name having count(*)&1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
Where (a.字段1, a.字段2) In (Select 字段1, 字段2 From 表 Group By 字段1, 字段2 Having Count(*) & 1) And
&& Rowid Not In (Select Min(Rowid) From 表 Group By 字段1, 字段2 Having Count(*) & 1)
查单个字段的重复次数
Select Name,sex,Count(*) From A Group By Name,sex Having Count(*) & 1
延伸阅读:
频道总排行
频道本月排行本帖子已过去太久远了,不再提供回复功能。数据库表中数据行去重复1.建表CREATE TABLE `demo_table` (& `id` int(10) unsigned NOT NULL,& `name` char(255) NOT NULL,& `email` char(255) NOT NULL,& PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;2.插入数据,并尝试建立唯一索引INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;1&#39;, &#39;u1&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;2&#39;, &#39;u2&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;3&#39;, &#39;u3&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;4&#39;, &#39;u4&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;5&#39;, &#39;u5&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;6&#39;, &#39;u6&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;7&#39;, &#39;u7&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;8&#39;, &#39;u8&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;9&#39;, &#39;u9&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;10&#39;, &#39;u10&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;11&#39;, &#39;u11&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;12&#39;, &#39;u12&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;13&#39;, &#39;u13&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;14&#39;, &#39;u14&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;15&#39;, &#39;u15&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES (&#39;16&#39;, &#39;u16&#39;, &#39;&#39;);INSERT INTO `test`.`demo_table` (`id`, `name`, `email`) VALUES<span class="pln" style="box-sizing: borderJava思考者(javaInThinker) 
 文章为作者独立观点,不代表大不六文章网立场
javaInThinker帮助众多开发者了解行业动态,获悉最新的行业技术,帮助开发者不只是从技术角度提升自己热门文章最新文章javaInThinker帮助众多开发者了解行业动态,获悉最新的行业技术,帮助开发者不只是从技术角度提升自己&&&&违法和不良信息举报电话:183-
举报邮箱:
Copyright(C)2016 大不六文章网
京公网安备78}

我要回帖

更多关于 电脑Acfun弹幕怎么关闭 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信