Select语句
一、基本查询
SELECT * FROM T_STUDENT ts ;
SELECT stu_name, college FROM t_student;
SELECT STU_NAME 名字,COLLEGE 院系 FROM t_student;
二、条件查询
SELECT * FROM T_STUDENT WHERE GENDER = '男';
SELECT * FROM t_student WHERE stu_name LIKE '--';
SELECT count(stu)stu_name,college FROM t_student
三、排序查询
SELECT stu_name, score FROM t_student ORDER BY score DESC;
SELECT stu_name, college,score FROM T_STUDENT ORDER BY COLLEGE ,SCORE DESC
四、排序查询
SELECT count(1) 问天一部人数 FROM T_STUDENT ts;
SELECT COUNT(stu_id) 智能工程学院人数 FROM T_STUDENT WHERE COLLEGE ='智能工程学院';
SELECT COUNT(stu_id) 大数据与软件学院人数 FROM t_student WHERE college = '大数据与软件学院';
SELECT COUNT(DISTINCT(COLLEGE)) 院系个数 FROM T_STUDENT;
五、聚合函数
SELECT AVG(score) FROM T_STUDENT ts;
六、分组查询
SELECT college,count(stu_id) FROM T_STUDENT GROUP BY COLLEGE;
SELECT college,count(stu_id) FROM T_STUDENT GROUP BY college ORDER BY count(stu_id);
SELECT college,avg(score)平均分 FROM T_STUDENT GROUP BY COLLEGE ;
SELECT college,avg(score)平均分 FROM T_student GROUP BY college ORDER BY avg(score) desc;
SELECT college,COUNT(1),AVG(score)平均分 FROM T_STUDENT ts GROUP BY COLLEGE HAVING COUNT(1)>2