筛选或者删除数据表中重复的数据

1.筛选重复的记录

http://stackoverflow.com/questions/8190541/deleting-duplicate-rows-from-sqlite-database

select s.*,t.[count]
from filelist as s
inner join (
select ProjectId,SensorId, FileName, count(*) as [count]
from filelist
group by SensorId, FileName
having count(*) > 1
) as t
on s.ProjectId = t.ProjectId and s.SensorId = t.SensorId and s.FileName = t.FileName

需要注意的是group by筛选出来的数据,只是重复数据中的1条

 

If you want to find duplicate data (by one or several criterias) and select the actualrows.

This should also work, maybe give it try. SELECT id, COUNT(id) FROM table1 GROUP BY id HAVING COUNT(id)>1;

I think this will work properly to search repeated values in a particular column.

SELECT gid_Sensorinfo, COUNT(gid_Sensorinfo)
FROM rel_testareasensor 
GROUP BY gid_Sensorinfo 
HAVING COUNT(gid_Sensorinfo)>1;

 

Example

列出重复的记录,以及每一个记录重复了多少次

SELECT   ViewName ,
         COUNT(ViewName) AS [Count]
FROM     dbo.tbm_vie_View
GROUP BY ViewName
HAVING   COUNT(ViewName) > 1;

 

 

 筛选出重复的数据,可以包含重复数据的所有列

SELECT ViewID ,
       DynamicEntityID ,
       ViewName ,
       ViewDescription
FROM   tbm_vie_View
WHERE  ViewName IN (   SELECT   ViewName
                       FROM     dbo.tbm_vie_View
                       GROUP BY ViewName
                       HAVING   COUNT(ViewName) > 1
                   );

 

 

 

2.删除重复的记录

 http://stackoverflow.com/questions/8190541/deleting-duplicate-rows-from-sqlite-database

You need a way to distinguish the rows. Based on your comment, you could use the special rowid column for that.

To delete duplicates by keeping the lowest rowid per (hash,d):

delete   from YourTable
where    rowid not in
         (
         select  min(rowid)
         from    YourTable
         group by
                 hash
         ,       d
         )

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值