zoukankan      html  css  js  c++  java
  • 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(1from Orders as b where a.Positioncode=b.Positioncode and
                      a.Startdate
    >=b.Startdate and a.Startdate<=b.Enddate) as Counts1,     
                
    --A的结束时间在B区间内的数量
                (select COUNT(1from 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 endas 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


  • 相关阅读:
    Gitlab安装与备份恢复
    Logstash使用grok插件解析Nginx日志
    SSH登录启用Google二次身份验证
    Nginx隐藏标识以及其版本号
    Nginx虚拟目录设置
    Tomcat虚拟目录设置
    sqlserver无法连接
    Howto: 如何将ArcGIS Server缓存移动到新服务器
    优酷网架构学习笔记
    .net中自定义过滤器对Response内容进行处理
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760181.html
Copyright © 2011-2022 走看看