OutStockDetailID GoodsID
1 200703010001
1 200703010001
1 200703010001
2 200703010005
2 200703010005
3 200703010007
3 200703010008
这一个表里的2个字段 如果OutStockDetailID和GoodsID的内容一摸一样就不显示,如果不一样(OutStockDetailID为3的对着GoodsID有2种)就显示出来 要怎么写?
1 200703010001
1 200703010001
1 200703010001
2 200703010005
2 200703010005
3 200703010007
3 200703010008
这一个表里的2个字段 如果OutStockDetailID和GoodsID的内容一摸一样就不显示,如果不一样(OutStockDetailID为3的对着GoodsID有2种)就显示出来 要怎么写?
insert into @t
select 1,'200703010001'
union all select 1,'200703010001'
union all select 1,'200703010001'
union all select 2,'200703010005'
union all select 2,'200703010005'
union all select 3,'200703010007'
union all select 3,'200703010008'
select * from @t;
select OutStockDetailID,GoodsID from @t group by OutStockDetailID,GoodsID having count(1)=1;
From Table_1 join (Select OutStockDetailID,Stdev(cast(GoodsID as int)) Count
From Table_1 Group By OutStockDetailID) temp on Table_1.OutStockDetailID=temp.OutStockDetailID and temp.Count>0
declare @t table(OutStockDetailID int,GoodsID char(12));
insert into @t
select 1,'200703010001'
union all select 1,'200703010001'
union all select 1,'200703010001'
union all select 2,'200703010005'
union all select 2,'200703010005'
union all select 3,'200703010007'
union all select 3,'200703010008'
union all select 4,'200703010001' --这里多加一条
select * from @t;
select OutStockDetailID,GoodsID from @t group by OutStockDetailID,GoodsID having count(1)=1
如果出库单明细对应的货号group by 后只有一条,那也是正常的数据,也就没有重复不重复这种概念
OutStockDetailID是出库明细 GoodsID是货号 现在我要查的是一条OutStockDetailID对应的好几种GoodsID的这种异常的数据 不知道讲明白了没有 THX~
select OutStockDetailID from
(select OutStockDetailID, GoodsID from tbl where isnull(OutStockDetailID,'')<>'' group by OutStockDetailID, GoodsID ) a
group by OutStockDetailID having count(*)>1
insert into @t
select 1,'200703010001'
union all select 1,'200703010001'
union all select 1,'200703010001'
union all select 2,'200703010005'
union all select 2,'200703010005'
union all select 3,'200703010007'
union all select 3,'200703010008'
union all select 4,'200703010001' --这里多加一条
select * from @t;
select OutStockDetailID from @t group by OutStockDetailID having count(1)>1;
select OutStockDetailID,GoodsID from @t group by OutStockDetailID,GoodsID having count(1)=1 and OutStockDetailID in(select OutStockDetailID from @t group by OutStockDetailID having count(1)>1)
insert into @t
select 1,'200703010001'
union all select 1,'200703010001'
union all select 1,'200703010001'
union all select 2,'200703010005'
union all select 2,'200703010005'
union all select 3,'200703010007'
union all select 3,'200703010008'
select * from @t group by OutStockDetailID, GoodsID having count(*)=1
insert into @t
select 1,'200703010001'
union all select 1,'200703010001'
union all select 1,'200703010001'
union all select 2,'200703010005'
union all select 2,'200703010005'
union all select 3,'200703010007'
union all select 3,'200703010008'
union all select 4,'200703010001'select * from @t
where OutStockDetailID in(
select a.OutStockDetailID from(
select distinct OutStockDetailID,GoodsID from @t) a
group by a.OutStockDetailID
having count(*) > 1)