查询数据:
select 字段名称 from 表名 的形式即可查询出想要的字段数据,例如你想在学生表里面查出学生的id号,姓名,年龄,性别,就可以用这种形式的查询方法。
select
student_id,
student_name,
student_age,
student_sex
from student_info
where 是一种限制语句,查询符合什么条件的数据。有的企业对表保存了很多分区,有专门的一个字段记录分区日期,那么你要限制一下日期,查询当天的数据。
select
student_id,
student_name,
student_age,
student_sex
from student_info
where pt='2023-01-01'
and 语法含义是并且的意思,在sql 中常用来做条件多重限制的语句。如果你想查询2023年1月1日 年纪为10岁的孩子,就可以写:
select
student_id,
student_name,
student_age,
student_sex
from student_info
where pt='2023-01-01'
and student_age=10
注意:一个查询语句至多只有一个where,条件直接用and连接
distinct 去重,数据可能会有重复值,如果需要去重,那么可以在select后面加一个distinct即可
例如:查询出学生年龄有那些
select
distinct
student_age
from student_info