您现在的位置是:主页 > news > 什么是网络建设/常州百度搜索优化

什么是网络建设/常州百度搜索优化

admin2025/5/3 4:43:32news

简介什么是网络建设,常州百度搜索优化,商场网站开发,网站建设php文件html文件全局查询 利用select显示所有的数据 select * from stuent;使用列别名改变查询结果的列标题 mysql语句: select sname name, year of birth: birth,2019-sage birthday,lcase(sdept) department from student;确定范围查询 使用谓词 between…and…以及not bet…

什么是网络建设,常州百度搜索优化,商场网站开发,网站建设php文件html文件全局查询 利用select显示所有的数据 select * from stuent;使用列别名改变查询结果的列标题 mysql语句: select sname name, year of birth: birth,2019-sage birthday,lcase(sdept) department from student;确定范围查询 使用谓词 between…and…以及not bet…

全局查询

利用select显示所有的数据

select * from stuent;

在这里插入图片描述

使用列别名改变查询结果的列标题

mysql语句:

select sname name, 'year of birth:' birth,2019-sage birthday,lcase(sdept) department from student;

在这里插入图片描述

确定范围查询

使用谓词 between…and…以及not between… and…

利用范围查询,查询年龄在20-30岁之间的学生的信息。

select *from student 
where sage between 20 and 30;

在这里插入图片描述
利用范围查询,查询年龄不在20-30岁之间的学生的信息。

select *from student 
where sage not between 20 and 30;

在这里插入图片描述

确定集合查询

使用谓词 in<值表>,not in <值表>
<值表>:用逗号分隔
例查询INS,MA,CS系别学生的名字和性别:

select sname ,ssex from student
where sdept in('IS','MA','CS');

在这里插入图片描述

字符串匹配查询

[NOT] LIKE ‘<匹配串>’ [ESCAPE ‘ <换码字符>’]
<匹配串>:指定匹配模板
匹配模板:固定字符串或含通配符的字符串
当匹配模板为固定字符串时,
可以用 = 运算符取代 LIKE 谓词
用 != 或 < >运算符取代 NOT LIKE 谓词

通配符

% (百分号) 代表任意长度(长度可以为0)的字符串
例:a%b表示以a开头,以b结尾的任意长度的字符串。如acb,addgb,ab 等都满足该匹配串
_ (下横线) 代表任意单个字符
例:a_b表示以a开头,以b结尾的长度为3的任意字符串。如acb,afb等都满足该匹配串

1) 匹配模板为固定字符串

查询学号为95001的学生表中的详细情况。

select *from student
where sno like '95001';

等价于:

select *from student
where  sno = '95001';

在这里插入图片描述
在这里插入图片描述

2)匹配模板为含通配符的字符串

例查询姓刘同学的姓名、学号和性别

select sname,sno,ssex from student
where sname like '刘%';

通配符只能用like 不能用等于
在这里插入图片描述
查询表中名字第二个字为‘三’的学生的名字和学号

select sname,sno from student
where sname like '_三%’;

在这里插入图片描述

多属性排序

查询全体学生的情况,查询的结果按所在系的系号升序排列,同一系的学生按年龄降序排序

select * from student 
order by sdept,sage desc;

在这里插入图片描述

使用集函数查找

类主要集函数

计数
COUNT([DISTINCT|ALL] *)
COUNT([DISTINCT|ALL] <列名>)
计算总和
SUM([DISTINCT|ALL] <列名>)
计算平均值
AVG([DISTINCT|ALL] <列名>)
求最大值
MAX([DISTINCT|ALL] <列名>)
求最小值
MIN([DISTINCT|ALL] <列名>)
DISTINCT短语:在计算时要取消指定列中的重复值
ALL短语:不取消重复值
ALL为缺省值

例计算总学生表的人数:
select count(*) from student;

在这里插入图片描述

计算计算机系的学生的最大年龄
select max(sage) from student
where sdept = 'CS';

在这里插入图片描述