批量修改数据、删除重复数据

本文介绍了一种使用SQL来计算特定ID的访问量的方法,并将计算得到的访问次数更新到主表中。此外,还提供了几种有效删除数据库中重复记录的SQL语句示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

根据ID计算该ID的访问量,并将该数值更新到主表
不知道还有没有好的方法

declare @table table (i_pid int,i_count int)
insert into @table(i_pid,i_count)
select   p_id ,COUNT(*) from  un_tbl_Visit  group by p_id

update  ProductOther set  Po_TotalDown=i_count from @table,ProductOther  where i_pid=P_ID

删除重复数据
1、delete   from   t1     where   exists(select   1   from   t1   a   where     a.id>t1.id   and   t1.col1=a.col1)   
2、alter   table   t1   add   (id   int   identity(1,1))   
  delete   from   t1    
  where   id   not   in   (select   min(id)   from   t1   group   by   column   having   count(*)   >   0)   

3、  delete   from   music   a1   where   a1.rowid<>(select   max(rowid)   from   music   a2   where   a1.id=a2.id   )  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值