使用LIKE删除重复行GROUP BY

时间:2012-05-08 06:18:22

标签: mysql sql json group-by duplicate-removal

我在数据库(mysql)中有一个字符串,如:

{"StateId":73,"CallTime":"\/Date(1336365498912+0500)\/","CallId":"1336365489.14157","Target":"agi://127.0.0.1"}},"Profile":{"$type":"DataWriter.DbProfile, DataWriterObjects","Name":"DataService","Provider":"mssql","ConnectionString":"Data Source=localhost\\mydb; Database=mydb; User Id=sa; Password=admin;"}}

该字符串是一个包含多个字段的JSON对象。问题是我有多个重复的行,我想从数据库中删除。如果 CallId StateId 相同但 CallTime 不同,则行被视为重复。首先,我想得到那些 CallId 相同的行的重复列表(GROUP BY),并忽略 CallTime 的差异。以下记录与第一个 CallId CallTime 不同,因此它被认为是重复的(基本上不需要考虑 CallTime 重复)

{"StateId":73,"CallTime":"\/Date(1336365498913+0500)\/","CallId":"1336365489.14157","Target":"agi://127.0.0.1"}},"Profile":{"$type":"DataWriter.DbProfile, DataWriterObjects","Name":"DataService","Provider":"mssql","ConnectionString":"Data Source=localhost\\mydb; Database=mydb; User Id=sa; Password=admin;"}}

那么我该如何进行GROUP BY?基本上,GROUP BY中的所有内容都应该匹配,忽略 CallTime 值。

表结构是

mysql> describe Statements;

+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| SequenceId | bigint(10)  | NO   | PRI | NULL    | auto_increment |
| Profile    | varchar(32) | YES  | MUL | NULL    |                |
| CacheItem  | text        | NO   |     | NULL    |                |
+------------+-------------+------+-----+---------+----------------+

之后我想删除重复项。有人帮帮我吗?

1 个答案:

答案 0 :(得分:1)

我认为您的数据库不够原子,您可能需要将JSON字符串拆分为单独的字段