select max(shop.[name]) as shopname,max(shop.shopid) as shopid,count(*) as provide from ticketinfo with(index(IX_ticketinfo)),shop where ticketinfo.shopid=shop.shopid and ticketinfo.providedate>'2007-03-26 00:00:00' and ticketinfo.providedate<'2007-03-26 23:59:59' group by ticketinfo.shopid order by provide DESC结果显示出来 只有3个字段 字段1是店名 字段2是店号 字段3是ticketinfo中每家店providedate条件中 一个计数  我现在想要的是结果中在加几个字段  比如字段4 也是count(*)也是ticketinfo表中的 可是条件还要加个ifprint=‘0’ 这样的语句在我的语句上怎么修改啊 帮帮忙好吗?谢谢!

解决方案 »

  1.   

    tryselect max(shop.[name]) as shopname,
    max(shop.shopid) as shopid,
    count(*) as provide,
    sum(case when [print]='0' then 1 else 0 end) as [print]
    from ticketinfo with(index(IX_ticketinfo)),shop 
    where ticketinfo.shopid=shop.shopid 
    and ticketinfo.providedate>'2007-03-26 00:00:00' 
    and ticketinfo.providedate<'2007-03-26 23:59:59' 
    group by ticketinfo.shopid 
    order by provide DESC
      

  2.   

    gahade(我们了解历史时,我们已成为历史) 
    大哥在帮我把这个两个结果组合起来好吗?让下面那个 显示在字段5好吗?谢谢select max(shop.[name]) as shopname,
    max(shop.shopid) as shopid,
    count(*) as provide,
    sum(case when ifprint='0' then 1 else 0 end) as ifprint
    from ticketinfo with(index(IX_ticketinfo)),shop 
    where ticketinfo.shopid=shop.shopid 
    and ticketinfo.providedate>'2007-03-26 00:00:00' 
    and ticketinfo.providedate<'2007-03-26 23:59:59' 
    group by ticketinfo.shopid 
    order by ifprint DESCselect max(shop.[name]) as shopname,max(shop.shopid) as shopid,count(*) as rcvcount from paylist_bak with(index(IX_paylist_bak)),shop where paylist_bak.shopid=shop.shopid and paylist_bak.rcvdate>'2007-03-26 00:00:00' and paylist_bak.rcvdate<'2007-03-26 23:59:59' group by paylist_bak.shopid