zoukankan      html  css  js  c++  java
  • hive_case

    case

    1、例:

    select u.uid,case 
    when u.birthday>='1990' and u.birthday<='1999' then '90 后' 
    when u.birthday>='1980' and u.birthday<='1989' then '80 后' 
    when u.birthday>='1970' and u.birthday<='1979' then '70 后' 
    when u.birthday>='1960' and u.birthday<='1969' then '60 后' 
    when u.birthday>='1950' and u.birthday<='1959' then '50 后' 
    else '其他' end as period from middle_bill_user u

    运行

    uid     period   
    1        90 后
    2        90 后
    3        80 后
    4        70 后
    5        90 后
    .....

    再处理

    select mbu.period, count(mbu.uid) as num from 
    (select u.uid,case 
    when u.birthday>='1990' and u.birthday<='1999' then '90 后' 
    when u.birthday>='1980' and u.birthday<='1989' then '80 后' 
    when u.birthday>='1970' and u.birthday<='1979' then '70 后' 
    when u.birthday>='1960' and u.birthday<='1969' then '60 后' 
    when u.birthday>='1950' and u.birthday<='1959' then '50 后' 
    else '其他' end as period from middle_bill_user u) mbu group by mbu.period; '

    结果

    period   num
    90后     121
    80后      20
    ....

      

  • 相关阅读:
    Airflow使用笔记
    公共关系学(第二版)笔记
    公众关系秘籍
    SQL SERVER XML 学习总结
    hadoop 1.2.1 配置
    ssh
    centos&windows的共享文件(通过挂载)
    代理设置(wget/yum)
    环境变量设置
    centos7 自定义服务
  • 原文地址:https://www.cnblogs.com/Jomini/p/12528416.html
Copyright © 2011-2022 走看看