Question[SQL]:如何计算重叠的天数(未完成...)

未完成...
http://www.cnblogs.com/springwind/archive/2008/06/28/1231527.html
http://topic.csdn.net/t/20061123/14/5179712.html

     with  arg1  as
    (
        
select  a. * ,
            
-- A的开始时间在B区间内的数量
            ( select   COUNT ( 1 from  Orders  as  b  where  a.Positioncode = b.Positioncode  and
                  a.Startdate
>= b.Startdate  and  a.Startdate <= b.Enddate)  as  Counts1,     
            
-- A的结束时间在B区间内的数量
            ( select   COUNT ( 1 from  Orders  as  b  where  a.Positioncode = b.Positioncode  and  
                a.Enddate
>= b.Startdate  and  a.Enddate <= b.Enddate)  as  Counts2 
            
from  Orders  as  a
    )
    
-- select * from arg1
     select  arg1.OrderID, arg1.Positioncode,
        (
case   when  arg1.Counts1 > arg1.Counts2  then  arg1.Counts1  else  arg1.Counts2  end as  Counts -- 哪个大以哪个
         from  arg1
            
inner   join  Product  as  p
                
on  arg1.Positioncode  =  p.Positioncode  and   -- 取重叠数大于显示数的项
                    p.Showcount < ( case   when  arg1.Counts1 > arg1.Counts2  then  arg1.Counts1  else  arg1.Counts2  end )
        
order   by  Positioncode


 

 

 

 

转载于:https://www.cnblogs.com/chenjunbiao/archive/2008/10/14/1760181.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值