当前位置: 首页 > news >正文

普陀网站开发培训学校西安网站建设方案优化

普陀网站开发培训学校,西安网站建设方案优化,优秀的网页设计图片,西安公司排行榜一、条件函数 if 条件函数 if函数是最常用到的条件函数&#xff0c;其写法是if(xn,a,b), xn代表判断条件&#xff0c;如果xn时&#xff0c;那么结果返回a ,否则返回b。 selectif(age < 25 or age is null, 25岁以下, 25岁以上) as age_cnt,count(1) as number from table…

一、条件函数

if 条件函数

   if函数是最常用到的条件函数,其写法是if(x=n,a,b),  x=n代表判断条件,如果x=n时,那么结果返回a ,否则返回b。

selectif(age < 25 or age is null, '25岁以下', '25岁以上') as age_cnt,count(1)  as number
from table1
group by age_cnt;

case when

case when 与if的作用基本相同,也是按照条件更换列中的内容,区别是case when 可以对 多个条件进行转换,需要注意的是:结尾需要加end作为结束标志

case 测试表达式
when 简单表达式1 then 结果表达式1
when 简单表达式2 then 结果表达式2
.......when 健达表达式n then 结果表达式n
[else 结果表达式 n+1]
end
--举例:
select case when age <25 or age is null then '25岁以下'else '25岁及以上'end as  age_cnt,
count(1) as  number
from table1 
group by age_cnt;-- 举例:
select device_id,gender,case when age<20 then '20岁以下'when age>=20 and age<=24 then '20-24岁'when age>=25 then '25岁及以上'else '其他'end as age_cut
from table1;

二、运用案例

2.1 行转列

问题描述

   

数据准备

 create table if not exists test(col1   string comment '',col2   string comment '',col3    string comment '') comment '测试表';insert overwrite table testvalues ('a','g','11'),('a','f','23'),('a','d','9'),('b','g','5'),('b','f','8'),('b','d','47');

数据分析

利用case  when 进行行转列

selectcol1,case col2 when 'g' then col3 else 0 end as g,case col2 when 'f' then col3 else 0 end as f,case col2 when 'd' then col3 else 0 end as d
from test;

 

 最后,分组求max值即可

selectcol1,max(case col2 when 'g' then col3 else 0 end) as g,max(case col2 when 'f' then col3 else 0 end) as f,max(case col2 when 'd' then col3 else 0 end) as d
from test
group by col1;

 最终的输出结果:

小结

http://www.hkea.cn/news/845072/

相关文章:

  • 服装网站首页设计主要推广手段免费
  • 网站建设公司做销售好不好?seo搜索引擎优化实训总结
  • 江西威乐建设集团有限公司企业网站长春关键词优化公司
  • 深圳网站建设lxhd英文关键词seo
  • 在线购物商城网站百度移动端排名软件
  • 太原网站的公司友情链接的英文
  • 网站是用什么做的吗百度q3财报2022
  • 深圳福田网站建设公司如何做谷歌seo推广
  • 西安有做网站的吗北京网站设计公司
  • 哪家专门做特卖网站平台连接
  • 衢州网站推广最近发生的重大新闻
  • 网页设计的网站配色方案seo基础培训机构
  • 维护网站是什么工作淄博网站制作
  • 做电影下载网站成本淘宝关键词排名
  • 企业h5网站建设百度推广电话是多少
  • 中国保密在线网站培训系统软文怎么做
  • 山西住房城乡建设部网站整合网络营销是什么
  • 做美图网站有哪些东西吗个人博客seo
  • 南昌专业做网站公司竞价托管怎么做
  • 网站产品展示怎么做微信小程序建站
  • dw做网站的流程客户引流的最快方法是什么
  • 做网站app优惠活动的交换链接营销成功案例
  • 企业公示信息查询系统山西上海百度推广优化公司
  • 上海网站排名优化价格武汉百度快照优化排名
  • 做网站小程序如何做广告宣传与推广
  • 网站建设背景朝阳百度新闻网页
  • 专门做拼团的网站西安网站开发
  • 怎么看网站开发语言太原seo推广
  • 什么网站做宣传好新乡网站seo
  • 济南网站制作服务价格信息流优化师前景