两表合并后,去掉重复数据的问题(在线等)谢谢
因为数据很大,故按月存放,现在表 wx200703数据如下:
sh ph cd rq
lc1 055 66.80 20070315
lc1 055 66.30 20070320
lc1 056 66.40 20070315
lc1 056 65.90 20070320
lc1 057 63.60 20070315
lc1 057 63.10 20070320
。。。
表 wx200704数据如下:
sh ph cd rq
lc1 055 63.80 20070410
lc1 057 60.60 20070410
lc1 058 63.10 20070420
。。。
想查出两表合并后,sh,ph相同的情况下最后日期的数据:
sh ph cd rq
lc1 055 63.80 20070410
lc1 057 60.60 20070410
lc1 056 65.90 20070320
lc1 058 63.10 20070420
------解决方案--------------------select * from tab,(select sh,ph from tab group by sh,ph having count(sh) > 1 and count(ph) > 1) a where tab.sh = a.sh and tab.ph = a.ph
相同的记录
------解决方案--------------------if object_id( 'pubs..wx200703 ') is not null
drop table wx200703
go
create table wx200703(sh varchar(10),ph varchar(10),cd decimal(18,2),rq varchar(10))
insert into wx200703(sh,ph,cd,rq) values( 'lc1 ', '055 ', 66.80, '20070315 ')
insert into wx200703(sh,ph,cd,rq) values( 'lc1 ', '055 ', 66.30, '20070320 ')
insert into wx200703(sh,ph,cd,rq) valu