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

32-Hive SQL DML语法之查询数据

1.Select语法树

从哪里查询取决于FROM关键字后面的table_reference,
这是我们写查询SQL的首先要确定的事即你查询谁?
表名和列名不区分大小写。

在这里插入图片描述
案例:在数据集中有一份数据文件《us-covid19-counties.dat》,里面记录了2021-01-28美国各个县累计新冠确诊病例数和累计死亡病例数。

use liushao;
drop table if exists t_usa_covid19;
CREATE TABLE t_usa_covid19(count_date string,county string,-- 美国的县郡state string, -- 哪个洲fips int, --邮政编码cases int,--累计确诊病例deaths int)--死亡人数
row format delimited fields terminated by ",";-- 加载数据
load data local inpath '/export/data/hivedata/covid19-counties.dat' into table liushao.t_usa_covid19;select * from t_usa_covid19;--  1. 查询 美国鬼子  美国的县郡  哪个洲 死了多少人
select county,state,deaths from t_usa_covid19;select 1 from t_usa_covid19;-- 2.我想看一下你目前正在使用哪个数据库
select  current_database();--  3.匹配所有的行 (看 洲)
select state from t_usa_covid19;
-- 相当于
select all state from t_usa_covid19;-- 4.数据去除重复
select distinct state from t_usa_covid19;-- 5.使用条件
-- 一大于二十不成立的 返回 false ,不能查询到结果
select * from t_usa_covid19 where 1 > 2;-- 六等于六成立 返回 true ,能查询到结果
select * from t_usa_covid19 where 6 =6;-- 6.查找加利福尼亚州的 疫情数据
select * from t_usa_covid19 where state='California';--  7.使用一下函数  长度  length() 查询州字母长度超过10位的
select * from t_usa_covid19 where length(state)>10;--  8. 查询死亡人数超过100  的州  不能执行
--注意:where条件中不能使用聚合函数
-- --报错 SemanticException:Not yet supported place for UDAF ‘sum'
--聚合函数要使用它的前提是结果集已经确定。
--而where子句还处于“确定”结果集的过程中,因而不能使用聚合函数。
-- select state,sum(deaths) from t_usa_covid19 where sum(deaths)>100 group by state;select state,sum(deaths) from t_usa_covid19 group by state having sum(deaths)>100 ;--9 查询 美国共有多少个的县郡   结果是: 3245select  county from t_usa_covid19;select  count(county) as county_nums from t_usa_covid19;-- 去除重复的县郡  1930
select  count(distinct county) as county_nums from t_usa_covid19;-- 10 查询一下美国加州有多少个县
select count(county) from t_usa_covid19 where state='California';-- 11 统计德州总的死亡病例数
select sum(deaths) from  t_usa_covid19 where state='Texas';-- 12 统计美国最高确诊病例是哪个县
select  max(cases) from  t_usa_covid19;-- 回去 看看  group by   limit   order by  等 。。。
http://www.lryc.cn/news/613696.html

相关文章:

  • 《Hive、HBase、StarRocks、MySQL、OceanBase 全面对比:架构、优缺点与使用场景详解》
  • 安装部署K8S集群环境(实测有效版本)
  • K8s 常见故障案例分析
  • ArgoCD 与 GitOps:K8S 原生持续部署的实操指南
  • hive-日期拆分为多行
  • 二、k8s 1.29 之 网络
  • 2025年城市建设与智慧交通国际会议(ICUCIT 2025)
  • Vue复习
  • 暴力解决MySQL连接失败
  • 协同进化:AIGC、Agent和MCP如何相互促进共同发展
  • 内容分发机制研究:实测一款多源短视频聚合App
  • 医防融合中心-智慧化慢病全程管理医疗AI系统开发(上)
  • C++程序库选择:权衡与取舍的艺术——以iostream和stdio为例
  • 低压电工-------元器件认识
  • react+echarts实现个性化评分展示(类进度条)
  • AR眼镜:能源行业设备维护的“安全守护者”
  • Java 虚拟机之双亲委派机制
  • 接口自动化-pytest
  • 使用winsw把SpringBoot项目注册成window服务
  • Linux怎么查看时区信息?(Linux时区)(tzselect)
  • Xvfb虚拟屏幕(Linux)中文入门篇1:(wikipedia摘要,适当改写)
  • 容器 vs 虚拟机
  • 技法笔记3 | 验证交互式shell连接
  • 数据结构(五):顺序循环队列与哈希表
  • SkyWalking-1--SkyWalking是什么?
  • Kubernetes学习
  • 嵌入式开发学习———Linux环境下IO进程线程学习(六)
  • Qwen系列模型
  • 对比学习(Contrastive Learning)面试基础
  • STM32——STM32CubeMX