--语句一
select COUNT(id)  outbox from Message where fromId= 1 and fromUserType=2 and (fromDel is NULL or fromDel=0);
--语句二
select COUNT(id)  inbox from Message where toId= 1 and toUserType=2 and (toDel is NULL or toDel=0)分开执行显示
outbox
 31inbox
 
20 想达到如结果集
outbox inbox
31       20在SQL 2008中执行中下语句错误,网上一老兄说 select * from 
(select COUNT(id)  outbox from Message where fromId= 1 and fromUserType=2 and (fromDel is NULL or fromDel=0)),
(select COUNT(id)  inbox from Message where toId= 1 and toUserType=2 and (toDel is NULL or toDel=0))提示  错误  ,大侠帮帮 看看,谢谢!

解决方案 »

  1.   

    select outbox =
    (select COUNT(id)  outbox from Message where fromId= 1 and fromUserType=2 and (fromDel is NULL or fromDel=0)),
           inbox =
    (select COUNT(id)  inbox from Message where toId= 1 and toUserType=2 and (toDel is NULL or toDel=0))
      

  2.   

    select outbox =
    (select COUNT(id) from Message where fromId= 1 and fromUserType=2 and (fromDel is NULL or fromDel=0)),
           inbox =
    (select COUNT(id) from Message where toId= 1 and toUserType=2 and (toDel is NULL or toDel=0))
      

  3.   


    select sum(case when isnull(fromdel,0) =0 then 1 else 0 end)  outbox,
    sum(case when isnull(toDel ,0) =0 then 1 else 0 end) as inbox 
    from Message 
    where fromId= 1 and fromUserType=2 
      

  4.   

    select outbox=sum(case when isnull(fromDel,0)=0 then 1 else 0 end),
           inbox=sum(case when isnull(toDel,0)=0 then 1 else 0 end)
    from Message where fromId= 1 and fromUserType=2