select count(fcustomernames) from T_SHE_Purchase p
left join T_SHE_Room r on p.froomid=r.fid  and p.fstate='4AUDITTED'
where r.fbuildingarea<48
select count(fcustomernames) from T_SHE_Purchase p
left join T_SHE_Room r on p.froomid=r.fid  and p.fstate='4AUDITTED'
where r.fbuildingarea>=48 and r.fbuildingarea<55怎么把这两个拼成一个

解决方案 »

  1.   

    求总的就把俩where条件用 or 关联。
      

  2.   

    select count(case when r.fbuildingarea<48 then 1 else 0 end) as c1,
    count(case when r.fbuildingarea<48 then 0 else 1 end) as c2
     from T_SHE_Purchase p
    left join T_SHE_Room r on p.froomid=r.fid and p.fstate='4AUDITTED'
      

  3.   

    select count(case when r.fbuildingarea<48 then 1 else 0 end) as c1,
    count(case when  r.fbuildingarea>=48 and r.fbuildingarea<55  then 1 else 0 end) as c2
     from T_SHE_Purchase p
    left join T_SHE_Room r on p.froomid=r.fid and p.fstate='4AUDITTED'
      

  4.   

    select count(case when r.fbuildingarea<48 then 1 else 0 end) as c1,
    count(case when r.fbuildingarea>=48 and r.fbuildingarea<55 then 1 else 0 end) as c2
     from T_SHE_Purchase p
    left join T_SHE_Room r on p.froomid=r.fid and p.fstate='4AUDITTED'
      

  5.   

    上面的写法有问题,
    select 
           (case when r.fbuildingarea<48 then count(fcustomernames) else 0 end )
           (case when r.fbuildingarea>48 then count(fcustomernames) else 0 end )
    from T_SHE_Purchase p 
    left join T_SHE_Room r on p.froomid=r.fid  and p.fstate='4AUDITTED'
    这语法有问题,怎么改写下
      

  6.   

    有select
      count(case when r.fbuildingarea<48 then 1 else 0 end) as c1,
      count(case when r.fbuildingarea>=48 and r.fbuildingarea<55 then 1 else 0 end) as c2
    from
     T_SHE_Purchase p
    left join
     T_SHE_Room r 
    on
     p.froomid=r.fid 
    and
     p.fstate='4AUDITTED'
      

  7.   

    你的语句没错误,但数据不对,我写的那个是个样子,不是聚合,需要GROUP BY之类的吗,但我不知道应该怎么改写
      

  8.   

    select sum(case when r.fbuildingarea<48 then 1 else 0 end) as [小于48],
    sum(case when r.fbuildingarea>=48 and r.fbuildingarea<55 then 1 else 0 end) as [介于48-55之间]
    from T_SHE_Purchase p
    left join T_SHE_Room r on p.froomid=r.fid and p.fstate='4AUDITTED'