Sql Server 去重复数据
我的数据库中有一个Order表 里面字段为
orderId productID amount qty
100100 1010101 -100 -1
100100 1010101 100 1
100100 1010102 100 1
100100 1010103 100 1
现在 我想查询时 去掉这1010101这两条数据 不是删除 只是想查询时将这两天数据同时剔除
请各位大大 帮助下 谢谢
仅仅是去除这两条?什么规则呢?
SQL code:
if object_id('[Order]') is not null drop table [Order]
go
create table [Order] (orderId int,productID int,amount int,qty int)
insert into [Order]
select 100100,1010101,-100,-1 union all
select 100100,1010101,100,1 union all
select 100100,1010102,100,1 union all
select 100100,1010103,100,1
select *
from [Order] t
where exists(select 1
from [Order]
where orderId=t.orderId and productID=t.productID
group by orderId having count(*)=1)
/*
orderId productID amount qty
----------- ----------- ----------- -----------
100100 1010102 100 1
100100 1010103 100 1
*/
SQL code:
--------------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-04-02 14:59:07
-- Version:Microsoft
相关问答:
表
id bh
1 10
2 11
3 12
4 15
5 16
6 22
7 25
8 26
9 27
10 28
将bh按连续分段出来返回字符串:
10~12,15~16,22,25~28
SQL code:
declare @t tabl ......
sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
第一句:
select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je
from ht left join gfdm on ht.gfdm=gfdm.gfdm
join jh on ht.htbh=jh.hth
and ht.htbh not like'del%' and ht. ......