/** 鼠标样式 **/

mysql数据库DQL

参考链接:
https://blog.csdn.net/qq_45173404/article/details/115712758

DQL查询数据

1.基础查询

-- 查询全部学生
SELECT * FROM student;

-- 查询指定的字段
SELECT LoginPwd,StudentName FROM student;

-- 别名 AS(可以给字段起别名,也可以给表起别名)
SELECT StudentNo AS 学号,StudentName AS 学生姓名 FROM student AS 学生表;

-- 函数 CONCAT(str1,str2,...)
SELECT CONCAT('姓名',StudentName) AS 新名字 FROM student;

-- 查询系统版本(函数)
SELECT VERSION();

-- 用来计算(计算表达式)
SELECT 100*53-90 AS 计算结果;

-- 查询自增步长(变量)
SELECT @@auto_increment_increment;

-- 查询有哪写同学参加了考试,重复数据要去重
SELECT DISTINCT StudentNo FROM result;

2.条件查询

-- 查询考试成绩在95~100之间的
SELECT StudentNo,StudentResult FROM result
WHERE StudentResult>=95 AND StudentResult<=100;

SELECT StudentNo,StudentResult FROM result
WHERE StudentResult>=95 && StudentResult<=100;
-- BETWEEN AND
SELECT StudentNo,StudentResult FROM result
WHERE StudentResultBETWEEN 95 AND 100;

-- 查询除了1000号以外的学生
SELECT StudentNo,StudentResult FROM result
WHERE StudentNo!=1000;
-- NOT
SELECT StudentNo,StudentResult FROM result
WHERE NOT StudentNo=1000;

-- 查询名字含d的同学
SELECT StudentNo,StudentName FROM student
WHERE StudentName LIKE '%d%';

-- 查询名字倒数第二个为d的同学
SELECT StudentNo,StudentName FROM student
WHERE StudentName LIKE '%d_';

-- 查询1000,1001学员
SELECT StudentNo,StudentName FROM student
WHERE StudentNo IN (1000,1001);

聚合函数

image

3.分组查询

image

=====

image

=====

image

4.排序查询

image

用orderby排序
asc是默认的从小到大,desc是从大到小;

image

先按age反排序,age相同时再按sex正排序;

5.分页查询

image

用limit查看数据 0,1是看第一条; 2,5是看第3至7共5条数据;

6.DQL执行顺序

image

posted @ 2024-03-25 22:36  aliex23k65  阅读(9)  评论(0)    收藏  举报