select * from 的一些心得

如何简单运用好 select * from语句,在不同的函数下,有不同的先后顺序。

语法格式 (代表先后顺便)

(2)select 字段名 查询什么东西 

(1)from 表名,从哪个表查询 

例如:查询所有学生姓名

select name

from stu;

(3)select 字段名 查询什么东西 

(1)from 表名,从哪个表查询 

(2)where 表达式,条件 要通过什么来查询

例如:查询所有女学生的信息

select *

from stu

where sex ='女';

(3)select 字段名 查询什么东西 

(1)from 表名,从哪个表查询 

(2)where 表达式,条件 要通过什么来查询

(4)order by 字段名 or desc/asc 降序和升序,默认是升序

查询选修了课程编号为‘105‘的学生的学生编号,成绩,结果以降序排列

select student_no,grade

from sc

where course_no ='105' order by grade desc;

(4)select 字段名 查询什么东西 

(1)from 表名,从哪个表查询 

(2)where 表达式,条件 要通过什么来查询

  (3)  group by 字段名 (having函数)

(5)order by 字段名 or desc/asc 降序和升序,默认是升序

查询各个课程编号及相应的选课人数

select course_no,count(student_no)

from  sc 

group by counrse_no;

查询选修2门以上课程的学生学号

select student_no

from sc  

group by student_no

having count(course_no)>2;

原文地址:https://www.cnblogs.com/wangrongchen/p/7841624.html