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

Posted 幸福安康

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了group by 一条语句实现多条语句的效果相关的知识,希望对你有一定的参考价值。

    --一个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 一条语句实现多条语句的效果的主要内容,如果未能解决你的问题,请参考以下文章

ElasticsearchElasticsearch如何实现 SQL语句中 Group By 和 Limit 的功能

关于多条id相同,只取其中一条记录的sql语句

sql语句中的group by啥意思

sql语句中的group by啥意思

sql查询中如何用group by查询出完整的一行记录?

执行一条sql语句update多条不同值的记录实现思路