1、 查询语法
1.1 查询指定列
语法:select 列名称1,列名称2... from 表名称
eg: select id,name from student
1.2 查询所有列
语法:select * from 表名称
eg: select * from student
2、 条件过滤
2.1.语法:select * from 表名称 where 条件…
-
eg:查询所有男生信息
select * from student where sex = '男' -
eg: 查询分数大于50分的男生成绩和姓名
select name,math,sex from student where math > 50 and sex = '男' -
eg: 查询分数等于45或者等于56
select * from student where math = 45 or math = 56 -
eg: 查询分数在70-80分的学生信息
select * from student where math between 70 and 80 -
eg: 查询地址在湖北或者湖南的学生姓名和地址
select name,address from student where address in('湖北','湖南')
SQL基础教程:查询、过滤、聚合、排序与分组详解

本文详细介绍了SQL查询的基本语法,包括指定列或所有列的查询,条件过滤(包括元组、模糊查询等),聚合函数的使用,以及排序和分组的方法。此外,还提及了如何给字段起别名以提高代码可读性。
最低0.47元/天 解锁文章





