首页 文章 精选 留言 我的

精选列表

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

写了半天 东西都没了,瞬间整个人都凌乱了)

首先将练习用的两张表 上传到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

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

[python作业AI毕业设计博客]深入理解Flask 中英文版-英文更新至2018第2版 Mastering Flask Web Deve...

深入理解Flask - 2016.pdf Flask 是在Python 用户中最为流行的Web 开发框架。《深入理解 Flask》从一个简单的Flask 项目入手,由浅入深地探讨了一系列实战问题,包括如何使用SQLAlchemy 和Jinja 等工具进行Web 开发;如何正确地设计扩展性强的Flask 应用架构和搭建MVC 环境;对于各种NoSQL 数据库的特性,何时应该、何时不应该及如何使用它们;通过使用Flask 扩展快速实现用户的身份系统、RESTful API、NoSQL查询、后台管理等功能;如何创建自己的扩展;使用Celery 编写异步任务,使用pytest 进行单元测试等;最后介绍了如何部署上线,包括使用自己搭建的服务器或使用各种云服务,以及如何权衡和选择这些不同的解决方案。 英文版本:Mastering Flask -

资源下载

更多资源
Mario

Mario

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

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

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

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册