时间:2021-07-01 10:21:17 帮助过:15人阅读
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
DELETEFROM
people
WHERE
peopleName IN (
SELECT
peopleName
FROM
people
GROUP BY
peopleName
HAVINGcount(peopleName) > 1
)
AND peopleId NOT IN (
SELECTmin(peopleId)
FROM
people
GROUP BY
peopleName
HAVINGcount(peopleName) > 1
)
3、查找表中多余的重复记录(多个字段)
SELECT
*
FROM
vitae a
WHERE
(a.peopleId, a.seq) IN (
SELECT
peopleId,
seq
FROM
vitae
GROUP BY
peopleId,
seq
HAVINGcount(*) > 1
)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
DELETEFROM
vitae a
WHERE
(a.peopleId, a.seq) IN (
SELECT
peopleId,
seq
FROM
vitae
GROUP BY
peopleId,
seq
HAVINGcount(*) > 1
)
AND rowid NOT IN (
SELECTmin(rowid)
FROM
vitae
GROUP BY
peopleId,
seq
HAVINGcount(*) > 1
)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
SELECT
*
FROM
vitae a
WHERE
(a.peopleId, a.seq) IN (
SELECT
peopleId,
seq
FROM
vitae
GROUP BY
peopleId,
seq
HAVINGcount(*) > 1
)
AND rowid NOT IN (
SELECTmin(rowid)
FROM
vitae
GROUP BY
peopleId,
seq
HAVINGcount(*) > 1
)
6.消除一个字段的左边的第一位:
UPDATE tableName
SET [ Title ]= RIGHT ([ Title ],(len([ Title ]) - 1))
WHERE
Title LIKE ‘村%‘
7.消除一个字段的右边的第一位:
UPDATE tableName
SET [ Title ]= LEFT ([ Title ],(len([ Title ]) - 1))
WHERE
Title LIKE ‘%村‘
8.假删除表中多余的重复记录(多个字段),不包含rowid最小的记录
UPDATE vitae
SET ispass =- 1WHERE
peopleId IN (
SELECT
peopleId
FROM
vitae
GROUP BY
peopleId
来源: http://blog.csdn.net/z_youarethebest/article/details/53785435MySQL中删除重复数据只保留一条
标签:otto pad bsp font 保留 mil tom 来源 tle