查询语法:
SELECT
字段列表
FROM
表名列表
WHERE
条件列表
GROUP BY
分组字段
HAVING
分组后条件
ORDER BY
排序字段
LIMIT
分页限定;
(查询所有列时字段列表可以用*替换,但不要使用)
SELECT DISTINCT address FROM student;(DISTINCT去除重复数据)
SELECT address AS 地址 FROM student;(AS取别名,可省略)
--查询年龄20到30的学生的名字分数
SELECT name,score FROM student WHERE age>=20 && age<=30
SELECT name,score FROM student WHERE age>=20 AND age<=30
SELECT name,score FROM student WHERE age BETWEEN 20 AND 30
--查询出生日期1998-09-01到1998-09-10的学生的名字分数
SELECT name,score FROM student WHERE DATE BETWEEN '1998-09-01' AND '1998-09-10'
--查询年龄30的学生的名字分数
SELECT name,score FROM student WHERE age=30
--查询年龄非30的学生的名字分数
SELECT name,score FROM student WHERE age!=30
SELECT name,score FROM student WHERE age<>30
--查询年龄30或22的学生的名字分数
SELECT name,score FROM student WHERE age=30 OR age=22
--查询年龄为null的姓名成绩,null必须用is
SELECT name,score FROM student WHERE age IS NULL
模糊查询LIKE(_表单个任意字符,%表任意个字符)
--查询姓马的学员年龄
SELECT age FROM student WHERE name LIKE '赵%';
--查询第二个字是云的学员年龄
SELECT age FROM student WHERE name LIKE '_云%';
--查询名字中包含芸的学员年龄
SELECT age FROM student WHERE name LIKE '%芸';
网友评论