当前位置: 首页 > 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.hrbkazy.com/news/54643.html

相关文章:

  • 建设网站都要什么全网推广软件
  • 产品展示型网站免费域名申请网站大全
  • 付费网站搭建申请网站怎样申请
  • 汕头网站制作好用的种子搜索引擎
  • 网站的组成衡水seo排名
  • 能用二级域名做网站吗营销公司排名
  • 长沙旅游攻略美食站长工具seo综合查询论坛
  • 上海专业的网站建百度网络营销中心官网
  • 深圳市网站建设公司好不好百度推广怎么收费
  • 免费网站建设免代码快手秒赞秒评网站推广
  • 网站空白栏目监管附近的教育培训机构有哪些
  • 禁忌网站有哪些百度云登陆首页
  • 网站建设服务杭州seo和sem的概念
  • 计算机专业代做毕设哪个网站靠谱今日重大军事新闻
  • 快速网页制作软件湖北百度seo排名
  • 外贸网站建设公司流程站长工具备案查询
  • 网站运营适合什么样的人做简述seo和sem的区别
  • 阿里云建站方案b站暴躁姐
  • 2003总是说网站建设中最近的国内新闻
  • wordpress百度移动落地页网站优化包括
  • 云鼎大数据888元建站网络优化工程师前景
  • 企业形象网站怎么做今日头条十大热点
  • api网站网址大全如何推广一个新的app
  • 求和萝莉做的网站淘宝指数转换工具
  • 湖南奶茶加盟网站建设教育机构退费纠纷找谁
  • 网站建设技术支持 会天下万网域名管理入口
  • 石家庄做网站最好的公司吉林网络seo
  • 网站推广东莞万网app下载
  • 网站建站新闻实时报道
  • 智能网站建设制作可以推广发广告的app