# 竹山一叶

:: :: :: :: :: :: :: ::
 390 随笔 :: 0 文章 :: 0 评论 :: 0 引用

1、查找表中多余的重复记录，重复记录是根据单个字段（peopleId）来判断

SELECT
*
FROM
people
WHERE
peopleId IN (
SELECT
peopleId
FROM
people
GROUP BY
peopleId
HAVINGcount(peopleId) > 1
)123456789101112131415123456789101112131415

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
)
1234567891011121314151617181920212223242512345678910111213141516171819202122232425

3、查找表中多余的重复记录（多个字段）

SELECT
*
FROM
vitae a
WHERE
(a.peopleId, a.seq) IN (
SELECT
peopleId,
seq
FROM
vitae
GROUP BY
peopleId,
seq
HAVINGcount(*) > 1
)12345678910111213141516171234567891011121314151617

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
)123456789101112131415161718192021222324252627123456789101112131415161718192021222324252627

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
)1234567891011121314151617181920212223242526272812345678910111213141516171819202122232425262728

6.消除一个字段的左边的第一位：

UPDATE tableName
SET [ Title ]= RIGHT ([ Title ],(len([ Title ]) - 1))
WHERE
Title LIKE '村%'12341234

7.消除一个字段的右边的第一位：

UPDATE tableName
SET [ Title ]= LEFT ([ Title ],(len([ Title ]) - 1))
WHERE
Title LIKE '%村'12341234

8.假删除表中多余的重复记录（多个字段），不包含rowid最小的记录

UPDATE vitae
SET ispass =- 1WHERE
peopleId IN (
SELECT
peopleId
FROM
vitae
GROUP BY
peopleId

posted on 2017-06-15 11:23  竹山一叶  阅读(442)  评论(0编辑  收藏