SQL 语句

本文由用户“sbl2007”分享发布 更新时间:2022-01-21 22:39:43 举报文档

以下为《SQL 语句》的无排版文字预览,完整格式请下载

下载前请仔细阅读文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。

SQL 语句

1、DISTINCT 去除重复 (SELECT DISTINCT *(需要去除重复数据的列) FROM *)

2、Limit 限制语句 (select *( 查询需要的数据) from *(表明) limit *(输入需要看到的几行))

3、AS 重命名,(select * AS *(需要更改的名字) FROM * LIMIT 1,5(2到6行))

4、Where 条件语句 (SELECT *(需要显示的列) FROM * WHERE *(需要查询的列名)="* (条件)")

5、Between操作符选取介于两个值之间的数据范围内的值 and连接(SELECT* FROM * WHERE * BETWEEN * and *)

6、排除不想看的列可以用 != 或者not in

(select device_id, gender, age, university from user_profile where university not IN ('复旦大学'))

(select device_id, gender, age, university from user_profile where university != '复旦大学')

7、is not null(查询不是空值),between 也可以 ,!=也可以

(select device_id, gender, age, university from user_profile where age !="null")

(select device_id, gender, age, university from user_profile where age BETWEEN 20 and 25)

(select device_id, gender, age, university from user_profile where age is not NULL)

8、where and 双条件语句 (select device_id, gender, age, university ,gpa from user_profile where gpa>"3.5"and gender="male")

9、or或语句,某某条件或某某条件(select device_id, gender, age, university ,gpa from user_profile where gpa>"3.7"or university="北京大学")

10、where in (select device_id,gender,age,university,gpa from user_profile where university in('北京大学','复旦大学','山东大学'))

11、 not in( select device_id,gender,age,university,gpa from user_profile where university not in('浙江大学'))

12、 混合语句and的优先级大于or 我这里写大括号方便区分,表示两个条件或两个条件

select device_id,gender,age,university,gpa from user_profile where (university='山东大学and gpa>3.5 ) or (university="复旦大学" and gpa>3.8)

13、like 模糊查询 (select devi 内容过长,仅展示头部和尾部部分文字预览,全文请查看图片预览。 '

例25.查询学生表中姓‘张’、姓‘李’和姓‘刘’的学生的情况。

SELECT * FROM 学生表 WHERE 姓名 LIKE '[张李某某]%’

例26.查询学生表表中名字的第2个字为“小”或“大”的学生的姓名和学号。

SELECT 姓名,学号 FROM 学生表 WHERE 姓名 LIKE '_[小大]%'

例27.查询学生表中所有不姓“刘”的学生。

SELECT 姓名 FROM 学生 WHERE 姓名 NOT LIKE '刘%’

例28.从学生表表中查询学号的最后一位不是2、3、5的学生信息。

SELECT * FROM 学生表 WHERE 学号 LIKE '%[^235]'

15、

[文章尾部最后300字内容到此结束,中间部分内容请查看底下的图片预览]

以上为《SQL 语句》的无排版文字预览,完整格式请下载

下载前请仔细阅读上面文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。

图片预览