zoukankan      html  css  js  c++  java
  • 固定行列转换加分段统计

    --1、办公  2、餐饮  3、商业  4、酒店  5、其他
    select (case when (ci_area>=0 and ci_area<=500) then '1-500' when (ci_area>=501 and ci_area<=1000) then '500-1000' else '一千以上' end) a,
    sum(case when ci_leixing=1 then 1 else 0 end) as '办公',
    sum(case when ci_leixing=2 then 1 else 0 end) as '餐饮',
    sum(case when ci_leixing=3 then 1 else 0 end) as '商业',
    sum(case when ci_leixing=4 then 1 else 0 end) as '酒店',
    sum(case when ci_leixing=5 then 1 else 0 end) as '其他'
    from zab_clientInfo 
    where ci_designerid=60
    group by 
    case when (ci_area>=0 and ci_area<=500) then '1-500' when (ci_area>=501 and ci_area<=1000) then '500-1000' else '一千以上' end  
    order by a

    参考方法:1.用sql语句实现年龄分段统计

    select case when (age >=10 and age <=20) then '10-20' when (age >=21 and age <=30) then '21-30'  else '30-' end 'eag_layer', count(*) emps from emp
    
    group by 
    
    case when (age >=10 and age <=20) then '10-20' when (age >=21 and age <=30) then '21-30'  else '30-' end
    
    order by 1

    2.查询列数固定sql

    select sname as 姓名,
    
    max(case course when '语文' then score else 0 end) 语文,
    
    max(case course when '数学' then score else 0 end) 数学,
    
    max(case course when '物理' then score else 0 end) 物理,
    
    from scores
    
    group by sname

  • 相关阅读:
    9-2 链表
    transient
    获取当前电脑的ip地址
    LinkList
    Java代码模拟链表
    什么是复合主键
    wp8 入门到精通
    C# 从入门到精通
    wp8 json2csharp
    wp8 安装.Net3.5
  • 原文地址:https://www.cnblogs.com/tianrui/p/3314227.html
Copyright © 2011-2022 走看看