1.select COUNT(distinct yj_jhdh)as 总单号 from rm_yj
2.select COUNT(distinct yj_jhdh)as 达标单号 from rm_yj where YJ_wlsj<6 
3.select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)as 物流时间 from rm_yj
4.select SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 平均周期 from rm_yj 
5.select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)+SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 总平均时间 from rm_yj 
如何把上面5条语句连起来,得出下面这样的结果
总单号 达标单号 物流时间 平均周期 总平均时间
500 390 4 15 19

解决方案 »

  1.   


    select 
    (select COUNT(distinct yj_jhdh)as 总单号 from rm_yj)
    ,(select COUNT(distinct yj_jhdh)as 达标单号 from rm_yj where YJ_wlsj<6 )
    ,(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)as 物流时间 from rm_yj)
    ,(select SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 平均周期 from rm_yj )
    ,(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)+SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 总平均时间 from rm_yj )
      

  2.   

    select 
    总单号=(select COUNT(distinct yj_jhdh)as 总单号 from rm_yj)
    达标单号=(select COUNT(distinct yj_jhdh)as 达标单号 from rm_yj where YJ_wlsj<6 )
    物流时间=(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)as 物流时间 from rm_yj)
    平均周期=(select SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 平均周期 from rm_yj )
    总平均时间=(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)+SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 总平均时间 from rm_yj )
      

  3.   

    select 
    总单号=(select COUNT(distinct yj_jhdh)as 总单号 from rm_yj),
    达标单号=(select COUNT(distinct yj_jhdh)as 达标单号 from rm_yj where YJ_wlsj<6 ),
    物流时间=(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)as 物流时间 from rm_yj),
    平均周期=(select SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 平均周期 from rm_yj ),
    总平均时间=(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)+SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 总平均时间 from rm_yj )
      

  4.   

    select 
    (select COUNT(distinct yj_jhdh)as 总单号 from rm_yj)
    ,(select COUNT(distinct yj_jhdh)as 达标单号 from rm_yj where YJ_wlsj<6 )
    ,(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)as 物流时间 from rm_yj)
    ,(select SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 平均周期 from rm_yj )
    ,(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)+SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 总平均时间 from rm_yj )
      

  5.   


    declare @x1 int,@x2 int
    declare @n1 float,@n2 float,@n3 floatselect @x1=COUNT(distinct yj_jhdh)as 总单号 from rm_yj
    select @x2=COUNT(distinct yj_jhdh)as 达标单号 from rm_yj where YJ_wlsj<6 
    select @n1=SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)as 物流时间 from rm_yj
    select @n2=SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 平均周期 from rm_yj 
    select @n3=SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)+SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 总平均时间 from rm_yj select @x1 as 总单号,@x2 as 达标单号,@n1 as 物流时间,
    @n2 as 平均周期,@n3 as 总平均时间试试效率上有变化吗?
      

  6.   

    select 
    总单号=(select COUNT(distinct yj_jhdh)as 总单号 from rm_yj),
    达标单号=(select COUNT(distinct yj_jhdh)as 达标单号 from rm_yj where YJ_wlsj<6 ),
    物流时间=(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)as 物流时间 from rm_yj),
    平均周期=(select SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 平均周期 from rm_yj ),
    总平均时间=(select SUM(case when yj_wlsj<6 then yj_wlsj else 0 end)/COUNT(distinct yj_jhdh)+SUM(yj_lxsj)/COUNT(distinct yj_jhdh)as 总平均时间 from rm_yj )