日期:2014-05-17 浏览次数:20625 次
select count(distinct 序列号)--这个查出来是6
from Return
where time between 11月 and getdate() --这里不同
select count(distinct 序列号) --这个查出来是100
from Shipment
where time between 12月 and getdate()
select count(distinct 序列号)--这个查出来是7
from Return
where time between 前9 and 前8
select count(distinct 序列号) --这个查出来是140
from Shipment
where time between 前9 and 前8
;with cte as(
select (
select count(distinct 序列号) from Return
where time between 11月 and getdate()
) 退回数,
(select count(distinct 序列号) from Shipment
where time between 12月 and getdate()
) 发货数
union all
select (
select count(distinct 序列号)from Return
where time between 前9 and 前8
),
(select count(distinct 序列号) from Shipment
where time between 前9 and 前8
)
union all...
)
select *,cast(退回数*100.0/发货数 as varchar(20))+'%' from cte