日期:2014-05-17 浏览次数:20625 次
if OBJECT_ID('INVML') is not null drop table INVML
create table INVML
(
ML009 int,
ML005 int
)
insert into INVML
select 22,24 union
select 50,50 union
select 50,50 union
select 10,22 union
select 20,20 union
select 22,23 union
select 22,24 union
select 21,24 union
select 30,21
SELECT ML009,SUM(ML005) AS 超入数量 FROM
(
select ML009,ML005 from INVML where ML009<>ML005
union all
select distinct ML009,ML005 from INVML where ML009=ML005
) A GROUP BY ML009
if OBJECT_ID('INVML') is not null drop table INVML
create table INVML
(
ML009 int,
ML005 int
)
insert into INVML
select 22,24 union
select 50,50 union
select 50,50 union
select 10,22 union
select 20,20 union
select 22,23 union
select 22,24 union
select 21,24 union
select 30,21
SELECT ML009,SUM(ML005) AS 超入数量 FROM
(
select ML009,ML005 from INVML where ML009<>ML005
union all
select top 1 ML009,ML005 from INVML where ML009=ML005 order by NEWID() --随机一个
) A GROUP BY ML009