首页 文章 精选 留言 我的

精选列表

搜索[sql server],共10000篇文章
优秀的个人博客,低调大师

Hive SQL 练习(这个秒退是怎么回事啊?写了半天 东西都没了,瞬间整个人都凌乱了)

首先将练习用的两张表 上传到hdfs上命令如下:hadoop fs -put /opt/dep.txt /dep.txthadoop fs -put /opt/employee.txt /employee.txt 然后开始写练习 创建数据库create database bs17;use bs17;创建员工信息表create table employee( emp_id string ,emp_name string ,status string ,salary string ,status_salary string ,in_work_date string ,leader_id string ,dep_id string )row format delimitedfields terminated by 't' row format delimited fileds terminated by 't' 表示将传进来的文件按照空格分割 写入到表格中 闯入文件 employee.txtload data inpath '/employee.txt' overwrite into table employee; 查询表 select * from employee; 同理创建第二个表create table department( dep_id string ,dep_name string ,address string )row format delimited fields terminated by 't'传入文件 以空格分割写入到表格中load data inpath '/dep.txt'overwrite into table department;查询表select * from department之前的创建表 都是采用string字段 这样做的原因是防止传入的数据损失精度失真 以原文件的格式类型为准 txt 通用 string接下来通过 as 来更改表结构 将字段改为所需要的create table dw_employee as select cast(emp_id as int) emp_id,emp_name,status,cast(salary as double)salary,cast(status_salary as double)status_salary,cast(in_work_date as date)in_work_date,cast(leader_id as int)leader_id,cast(dep_id as int)dep_idfrom employee dw_employee 为创建好的更改好字段的表select * from dw_employee查询表结构语句describe formatted dw_employee同理更改第二张表的表结构create table dw_department asselect cast(dep_id as int)dep_id,dep_name,addressfrom department select * from dw_department除了 通过 as 复制表 之外 还可以通过 like 来克隆 不过 like 克隆的只有表结构 没有数据create table employee_clone like employee;select * from employee_clone 查找employee 表中的 id name 月薪 季薪 年薪select emp_id ,emp_name ,salary mon_salary ,salary*3 season_salary ,salary*12 year_salary from dw_employee 查找员工的月工资 月薪加奖金select emp_id ,emp_name ,salary+status_salary getMoney from dw_employee 插入数据 id name 其他为null insert into dw_employee(emp_id,emp_name) values(1111,'aaaa') nvl 表示条件 如果有字段信息 则表示字段信息 如果为null 则用后的表示如有职位 则表示 没有则用普通员工代替 如果有入职日期 则表示 没有 则用2015-5-1表示select emp_id ,emp_name ,nvl(status,'普通员工') job ,nvl(in_work_date,'2015-5-1') in_work_date from dw_employee 复制员工表,表名为emp_copycreate table emp_copy as select * from dw_employee机构中有多少种职位(就是将所有的status 聚合展示出来 展示出来几种就有几种)select distinct status from dw_employee 薪水高于6000的员工 select * from dw_employee where salary>6000 职位是analyst 的员工 select * from dw_employee where status ='analyst' 以小写格式展示职位信息(lower())select emp_id ,emp_name ,lower(status) from dw_employee忽略大小写匹配职位等于‘ANALYST’的记录select * from dw_employee where upper(status)='ANALYST' 查询出薪水在5000到8000之间的员工(between and)select * from dw_employee where salary between 5000 and 8000;查询出2016年入职的员工select * from dw_employee where year(in_work_date)=2016 薪水不在5000到8000的员工select * from dw_employee where salary not between 5000 and 8000; 查询出职位是Manager或者analyst的员工select * from dw_employee where status in(Manager,analyst); 模糊查询like % 查询出没有岗位工资的员工select * from dw_employee where status_salary is null; 查询有岗位工资的员工select * from dw_employee where status_salary is not null; 查询出不在10部门和不再30部门的员工select * from where dw_employee where dep_id not in(10,30) DDL 数据定义语言insert select create table employee_leader like dw_employee insert into dw_employee_leader select * from dw_employee where leader_id is null insert overwrite table dw_employee_leader select * from dw_employee where leader_id is null 排序问题oder by 升序 asc 降序 descselect * from dw_employee order by salary desc; hive 的order by 全排序是通过只设置一个reducer 节点的方式来实现的通过hive可以很轻松的实现二次排序select * from dw_employee order by salary desc,salary_status desc; 查询多少个员工select count(*) from dw_employee 分组表达式 Group by 聚合函数 Count max min avg sum查询有多少个员工select count(*) from dw_employee查询有多少个姓张的员工select count(*) from dw_employee where emp_name like '%张%'计算员工的总薪水是多少select sum(salary) from dw_employee 计算员工的人数总和、薪水综合、平均薪水,最高薪水、最低薪水select count(*) ,sum(salary) ,avg(salary) ,max(salary) ,min(salary) from dw_employee 求出每个部门的最高薪水、最低薪水、平均薪水、总薪水、总人数selectcount(*) ,sum(salary) ,avg(salary) ,max(salary) ,min(salary) from dw_employeegroup by dep_id; ----求出总人数超过两人的部门的最高 最低 平均 总薪水 selectcount(*) ,sum(salary) ,avg(salary) ,max(salary) ,min(salary) from dw_employeegroup by dep_id;having count(*)>2 having 的作用 是在聚合后做一次删选 Having 用来对分组后的结果进行进一步的过滤 select * from dw_employee where salary in (select max(salary) from dw_employee) -----in 在后面添加子查询结果作为判断条件 如果子查询中有索引的话 in 是用不到这个索引 因此 in对接子查询的效率最低 子查询 查询出最高薪水的人的信息 select * from dw_employee where salary in (select max(salary) from dw_employe)最低薪水的人 select * from dw_employee where salary in (select min(salary) from dw_employe) 工资高于平均薪水的人的信息目前 hive目前不支持子查询的非等值查询所以使用 笛卡尔 乘积的方式 因为参数原因 不允许使用笛卡尔 乘积 所以需要通过指令设置一下让它允许set hive.strict.checks.cartesian.product=falseselect a.* ,b.* from dw_employee a, (select avg(salary)avesalary from dw_employee)bwhere a.salary >b.avgsalary谁的薪水比小赵的薪水高select a.*from dw_employee a,(select salary from dw_employee where emp_name='小赵')b where a.salary>b.salary研发部有哪些职位select status from dw_employee a where exists(select dep_id from department b where dep_name ='研发部' and a.dep_id =b.dep_id) ALL 子查询 Any(子查询) 谁是妖姬的同部门的同事select * from dw_employee where dep_id in(select dep_id from dw_employee where emp_name ='妖姬') 如果有两个叫妖姬 谁是妖姬的同事??? inner join 是两张表根据关联条件 相互过滤 能够关联上的数据才会出现在结果集中 Exists not existsunion 去重union all 不去重 薪水大于8000或者小于2000或者等于5000的员工select * from dw_employee where salary>8000unionselect * from dw_employee where salary <2000unionselect * from dw_employee where salary=5000 交集 intersect 差集 minus lefter outer join right outer join

优秀的个人博客,低调大师

阿里云大数据ACP认证知识点梳理6——基础SQL语句(内建函数、窗口函数规则、隐式转换规则)

abs(null)=null abs(-1)=1 abs(-1.2)=1.2 abs("-2")=2.0 abs(122320837456298376592387456923748)=1.2232083745629837e32 注:当number为Double、Bigint或Decimal类型时。输入为Bigint,返回Bigint。输入为Double,返回Double类型。输入为Decimal,返回Decimal类型。若输入为String类型,会隐式转换为Double类型后参与运算,其它类型抛异常。若输入为null,则返回null。 ceil(1.1)=2 ceil(-1.1)=-1 注:向上取整,函数返回不小于输入值value的最小整数。Double类型或Decimal类型,若输入为String类型或Bigint类型,会隐式转换到D

优秀的个人博客,低调大师

livekit v1.13.3 更新全解析:Mock API Server、鉴权校验、数据追踪元数据、WHIP 码率统计与稳定性修复一次看懂

2026年7月15日,实时音视频基础设施项目 livekit 发布了 v1.13.3 版本。从这次更新内容来看,虽然版本号属于小版本迭代,但实际覆盖的方向并不“小”。它同时涉及 测试链路建设、鉴权能力完善、数据追踪结构增强、WHIP 接入质量观测、WebRTC 互操作性优化,以及会话通知机制修复。对于正在使用 livekit 的开发者、音视频平台架构人员、实时互动业务团队来说,这个版本非常值得认真关注。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册