目录
sql语句查询重复的数据
MYSQL 连续性问题求解
binlog
索引
sql语句查询重复的数据
查找所有重复 [标题] 的记录:
SELECT *
FROM t_info a
WHERE ((SELECT COUNT(*)
FROM t_info
WHERE Title = a.Title) > 1)
ORDER BY Title DESC
删除重复记录
1。删除全部重复记录(慎用)
Delete 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)
2。保留一条(这个应该是大多数人所需要的 _)
Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)
注:此处保留ID最大一条记录
MYSQL 连续性问题求解
create table grade(
num smallint not null,
score int(3) not null);
insert into grade values
(1,89),
(2,76),
(3,76),
(4,84),
(5,84),
(6,84),
(7,76),
(8,76),
(9,76);
查询至少连续出现3次的成绩
方法:使用多个自连表来实现(当查找的连续值过多时,运行效率过低)
select distinct(a.score) from grade as a, grade as b, grade as c
where a.score = b.score and b.score = c.score
and a.num = b.num + 1 and b.num = c.num+ 1
扩展:
insert into grade values
(1,89),
(2,90),
(3,91),
(4,84),
(5,84),
查询至少出现3次连续成绩的记录
binlog
MySQL Binlog温故知新_多则惑少则明的博客-CSDN博客如果你对以下问题感兴趣,请移步:1、MySQL如何实现主从数据库同步;2、如何解决数据一致性问题:操作数据库成功了,可能会更新redis失败;反之亦然。很难保证二者的完全一致https://blog.csdn.net/huazhongkejidaxuezpp/article/details/128377999?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168388297016800227489763%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168388297016800227489763&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-2-128377999-null-null.blog_rank_default&utm_term=%E7%B4%A2%E5%BC%95&spm=1018.2226.3001.4450
索引
MySQL 索引_多则惑少则明的博客-CSDN博客一、索引的类型1. 普通索引2. 唯一索引3. 全文索引(FULLTEXT)4. 单列索引、多列索引多个单列索引与单个多列索引的查询效果不同,因为执行查询时,MySQL只能使用一个索引,会从多个索引中选择一个限制最为严格的索引。5. 组合索引(最左前缀)平时用的SQL查询语句一般都有比较多的限制条件,所以为了进一步榨取MySQL的效率,就要考虑建立组合索引。例如上表中针...https://blog.csdn.net/huazhongkejidaxuezpp/article/details/89578452?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168388297016800227489763%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168388297016800227489763&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-89578452-null-null.blog_rank_default&utm_term=%E7%B4%A2%E5%BC%95&spm=1018.2226.3001.4450