码迷,mamicode.com
首页 > 其他好文 > 详细

group by 一条语句实现多条语句的效果

时间:2017-11-24 21:32:27      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:color   count   select   style   sum   ber   sel   pre   date   

    --一个sql 使用 group by 实现 4个 sql 的效果
        select ProjectNumber,ClientName,jx,sf,sum(count) as TotalCount from tlog 
        where StDate>=2017-10-01 and StDate<2017-11-01 
        group by ProjectNumber,ClientName,jx,sf
        
        -- jx=1 and sf=1 
        select ClientName,sum(Count) as TotalCount from tlog where 
        jx=1 and sf=1 
        and (StDate>=2017-10-01 and StDate<2017-11-01) 
         group by ClientName
        -- jx=1 and sf=0 
         select ClientName,sum(Count) as TotalCount from tlog where 
        jx=1 and sf=0 
        and (StDate>=2017-10-01 and StDate<2017-11-01) 
         group by ClientName
       --  jx=0 and sf=1 
         select ClientName,sum(Count) as TotalCount from tlog where 
        jx=0 and sf=1 
        and (StDate>=2017-10-01 and StDate<2017-11-01) 
         group by ClientName
        -- jx=0 and sf=0 
         select ClientName,sum(Count) as TotalCount from tlog where 
        jx=0 and sf=0 
        and (StDate>=2017-10-01 and StDate<2017-11-01) 
         group by ClientName

 

group by 一条语句实现多条语句的效果

标签:color   count   select   style   sum   ber   sel   pre   date   

原文地址:http://www.cnblogs.com/25miao/p/7892139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!