其他分享
首页 > 其他分享> > DQL 查询数据(最重点)

DQL 查询数据(最重点)

作者:互联网

指定字段查询

-- 查询全部学生, select 字段 from 表
select * from student
-- 查询指定字段
select `studentno`,`loginpwd` from student
-- 别名,给结果起一个名字
select `studentno` as 学号, `loginpwd` as 登录密码 from student
-- 函数
select CONCAT('姓名: ', studentname) as 新名字 from student

去重 distinct

select * from result
-- 只看studnetno 
select `studentno` from `result` 
-- 去重 distinct
select distinct `studentno` from `result`

数据库的列

-- 查询系统版本
SELECT VERSION()
-- 用来计算
select 100*3 as 结果
-- 查询自增的步长
SELECT @@auto_increment_increment 
--学生考试成绩+1分查看
select `studentno`,`studentresult`+1 as 加分后 FROM result

where 条件子句

-- ========== where ============
select `studentno`,`studentresult` from result 
where `studentresult`>=70 and `studentresult`<=90 ;
-- 模糊查询
select studentno,studentresult from result
where studentresult BETWEEN 50 and 70 ;
-- !=
SELECT studentno studentresult from result 
where studentno != 1000 ;
-- != 等于 not
select studentno studentresult from result
where not studentno = 1000

模糊查询

like % (喜欢一百分)

-- like 查询凡是刘姓 % 表示从0开始到不限字数
select `studentname` from `student`
where `studentname` like '刘%'
-- 查询刘后一个名字的
select `studentname` from `student`
where `studentname` like '刘_'
-- 查询凡是带嘉的名字
select `studentname` from `student`
where `studentname` like '%嘉%'

in

-- ================== in (具体一个或者多个值)====================
-- 查询具体学号学生
select `studentname`, `address`from student 
where `studentno` in (1000,1003,1002)
-- 查询学生地址 要具体全称
select `studentno`,`studentname`, `address`from student 
where `address` in ('广东深圳','陕西','北京','广东');
SELECT * FROM `student`
-- ============= not null ===============
select `studentno`,`studentname` , `sex`from `student`  -- 查询性别不为空的学生
where `sex`  is not  null

标签:studentname,--,where,查询,studentno,student,DQL,重点,select
来源: https://www.cnblogs.com/ahhh7931/p/16183973.html