cinvcode iprice ddate
010001 10 2008-01-01
020002 20 2009-01-05
010001 10 1008-01-01
010003 30 2009-03-31
010003 30 2009-03-31
。。
数据库中有很多类似于010001和010003这样的重复数据,我实际上只需要一行,怎样删除其它行?
010001 10 2008-01-01
020002 20 2009-01-05
010001 10 1008-01-01
010003 30 2009-03-31
010003 30 2009-03-31
。。
数据库中有很多类似于010001和010003这样的重复数据,我实际上只需要一行,怎样删除其它行?
解决方案 »
- select Convert(varchar(20), getdate(),112)
- 怎样根据部门来统计参加会议的次数
- 用户表有自动编号得UID和用户名,都是唯一得,怎么建索引啊?
- 作业定时运行的问题
- 为什么我用 "select 姓名,日期,min(时间) as 上班时间,max(时间) as 下班时间 from TB group by 姓名,日期 " 得到的上班时间和下班时间
- 数据提供程序或其他服务返回E_FAIL状态问题,求助!!!
- BULK INSERT 的存储过程执行失败
- 对于同时数据达到百万级的数据库,我应该选择请那种人来开发这个?
- 一个无从下口的查询请人帮忙看看!我觉得挺难得!有兴趣的高手来看看!(非常急在线等待!)
- 关于视图的问题,等待解决
- 求一个文章ID关联到多个标签的存储过程
- 一个很简单的组合查询的问题
select distinct * from ta into #t
delete from ta where 1=1
insert ta select #t
where exists(select 1 from tb t where cinvcode=t.cinvcode and ddate>t.ddate)
truncate table tb
insert tb
select *
from #
delete tb
where exists(select 1 from tb t where cinvcode=t.cinvcode and ddate>t.ddate)
truncate table tb
insert tb
select * from #
--如果是删除完全一样 这样
select distinct * from ta into #t
delete from ta where 1=1
insert ta select * from #t漏东西了
truncate table tb
insert tb
select * from #
就样就行了
完全一样的用个临时表处理select distinct * into # from tb
truncate table tb
insert tb select * from #
drop table #
INSERT TBSELECT '010001' , 10 , '2008-01-01' UNION ALL
SELECT '020002' , 20 , '2009-01-05' UNION ALL
SELECT '010001' , 10 , '2008-01-01' UNION ALL
SELECT '010003' , 30 , '2009-03-31' UNION ALL
SELECT '010003' , 30 , '2009-03-31'--DROP TABLE TB--SELECT * FROM TB
SELECT IDD=IDENTITY(INT,1,1),* INTO # FROM TBDELETE # FROM # T WHERE EXISTS(SELECT 1 FROM # WHERE cinvcode=T.cinvcode AND IDD>T.IDD)SELECT * FROM #
IDD cinvcode iprice ddate
----------- ---------- ----------- ------------------------------------------------------
2 020002 20 2009-01-05 00:00:00.000
3 010001 10 2008-01-01 00:00:00.000
5 010003 30 2009-03-31 00:00:00.000(所影响的行数为 3 行)