SELECT [distinct] * | {colum1,colum2,,,} from table_name;
colum指定列名,* 代表查询所有 ,distinct 可选,是否踢掉重读数据
例
student表
select * from student;//所有
select id,name from student; //查询id和name列
select distinct name from studnet;//过滤重名的人
select english+10 from student;
显示加分数据不会修改。
select name ,English+Chinese from student;
select name as '姓名' ,English+Chinese as '总成绩' from student
as可以省略
select * from student where name ='XXX';
select * from student where english>90;
select * from student where english+Chinese>150;
用来统计函数
select count(*)|count(列名) from table_name [where balabala];
select count(*) from studnet;
1. select * from student where english>70;
2. select count(*) from student where english>70;
将符合条件的某列的和值
select sum(列名){,sum(列名)} from table_name [where balabala];
select sum(english) from student;
select sum(chinese)/count(*) from student;
求符合条件的平均值
select avg(列名){,avg(列名)} from table_name [where balabala];
select avg(english) from student;
select avg(chinese+english) from student;
求符合条件的列的最大值最小值
select max|min(列名) from tabname [where balabala];
select max(chinese+english) from studnet;
select * | column1,column2,column3,,,,from table_name order by column [asc升序|desc降序]
select name,math as '数学'from student order by math|‘数学’ asc;
select * | column1,column2,column3,,,,from table_name group by couumn [hive ....];
select name , sum(much) from prodect group by name;
where可以过滤,在分组前过滤,where中不允许使用聚合函数
select name , sum(much) from prodect group by name hive sum(much) >100;
select name,sun(much) from prodect where much <100 group by name hive sun(much)>100;
select * from tb_name limit [offset] 记录数量;
offset:开始位置默认从头。
表名或者字段名太长 可取小名代替。简化代码。
select * from tb_Name [as] 别名;
select 字段1 [as] 别名,字段2 [as] 别名 from tb_name;