sql | 基础总结 | 思维导图

看到好的文档,总结的很好,于是便将它按照我的理解来做了一番总结。


整体思路

整体把握,先从思维导图开始:
这里写图片描述

下面来细细分解。

基础语法

  • 关键字 select .. from .. where

查询

查询所有的

Select * from 表名 Select * from stuInfo

查询部分字段

Select 字段1,字段2,字段3from 表名 Select stuName,stuSex from stuInfo

去重复行DISTINCT

  • 关键字 DISTINCT

语法

select distinct 列名1 from 表名
  • 注意事项:DISTINCT必须放在所有列名前面

区间语句

  • 关键字 : between … and …

语法

Select * from score where degree between 60 and 80

指定条件语句

  • 关键字 : in

语法

select * from score where degree in (85,86,88)

AND语句

  • 关键字:and

语法

select * from score where degree>=60 and degree<=80

OR语句

  • 关键字 : or

语法

select * from student where class='95031‘ or Ssex='女'

排序语句

  • 关键字: order by

语法

select * from student order by class desc
  • 注意事项:ASC为升序 默认不写; DESC为降序

汇总语句

  • 关键字:count()

语法

select count(*) as CNT from student where class='95031'

求一列的最大值

  • 关键字:max

语法

select max(degree) From Score

求一列的最小值

  • 关键字:min

语法

select min(degree) From score

求平均值

  • 关键字:avg

语法

select avg(degree) as 课程平均分 from score where cno='3-105';

分组语句

  • 关键字: group by

语法

select cno, avg(degree) from score where cno like'3%‘ group by cno having count(*) >5
  • 注意事项:group by(字段名) having 条件,having来加条件限制

猜你喜欢

转载自blog.csdn.net/xxzhangx/article/details/78185714