当前位置: 首页 > news >正文

网站后台管理员怎么做常见的搜索引擎

网站后台管理员怎么做,常见的搜索引擎,漳浦建设银行网站,怎么给自己网站做搜索框文章目录 1. 注释2. 新增(Create)3. 查询(Retrieve)3.1 全列查询3.2 指定列查询3.3 查询字段为表达式3.4 别名3.5 去重: distinct3.6 排序: order by3.7条件查询3.8 分页查询 4. 修改 (update)5. 删除(delete)6. 内容重点总结 1. 注释 注释:在SQL中可以使用“–空格…

文章目录

  • 1. 注释
  • 2. 新增(Create)
    • 3. 查询(Retrieve)
    • 3.1 全列查询
    • 3.2 指定列查询
    • 3.3 查询字段为表达式
    • 3.4 别名
    • 3.5 去重: distinct
    • 3.6 排序: order by
    • 3.7条件查询
    • 3.8 分页查询
  • 4. 修改 (update)
  • 5. 删除(delete)
  • 6. 内容重点总结

1. 注释

注释:在SQL中可以使用“–空格+描述”来表示注释说明
CRUD 即增加(Create)、查询(Retrieve)、更新(Update)、删除(Delete)四个单词的首字母缩写。

2. 新增(Create)

语法insert into + 表名 + values (字段1, 字段2, ...), (字段1, 字段2, ...), ...其中字段1, 字段2, …对应了创建表时对应的位置. 如果要使插入的数据与相应的列相对应, 则可以insert into + 表名 + (列名1, 列名2, ...) values (字段1, 字段2, ...), (字段1, 字段2, ...), ...如果插入的数据量比设计表时数据量少就会给少的位置赋予null值. 具体操作举例如下:
我们先创建一张Student表, 具体设定如下
在这里插入图片描述
示例1 直接多行全列插入数据insert into student values(1,'张三'),(2, '李四');
在这里插入图片描述
示例2 多行指定列插入insert into student(name) values('王五'), ('赵六');
在这里插入图片描述

3. 查询(Retrieve)

语法

select[distinct] {* | {column [, column] ...} --字段[from table_name]--表名[where...]--查询条件[order by column [asc| desc], ...]--排序limit...--分表查询

着非常复杂, 下面我们来一步一步去拆分讲解.

---我们先创建一个考试成绩表, 并插入适当的数据, 方便我们接下来的分析
create table exam(id int, name varchar(20), chinese decimal(3, 1), math decimal(3, 1), english decimal(3, 1));insert into exam values
(1,'唐三藏', 67, 98, 56), 
(2,'孙悟空', 87.5, 78, 77), 
(3,'猪悟能', 88, 98.5, 90), 
(4,'曹孟德', 82, 84, 67),
(5,'刘玄德', 55.5, 85, 45),
(6,'孙权', 70, 73, 78.5),
(7,'宋公明', 75, 65, 30);

3.1 全列查询

-- 通常情况下不建议使用 * 进行全列查询
-- 1. 查询的列越多,意味着需要传输的数据量越大;
-- 2. 可能会影响到索引的使用。
mysql> select * from exam;

在这里插入图片描述

3.2 指定列查询

-- 指定列的顺序不需要按定义表的顺序来
select id, name, english from exam;

在这里插入图片描述

3.3 查询字段为表达式

-- 表达式不包含字段
select id, name, 10 from exam;
-- 表达式包含一个字段
select id, name, english+10 from exam;
-- 表达式包含多个字段
select id, name, chinese+math+english from exam;

在这里插入图片描述

3.4 别名

为查询结果中的列指定别名,表示返回的结果集中,以别名作为该列的名称,语法:

SELECT column [AS] alias_name [...] FROM table_name;
-- 结果集中,表头的列名=别名
select id, name, chinese+math+english as 总分 from exam;

在这里插入图片描述

3.5 去重: distinct

--通过查询得知98分重复了
select math from exam;
+------+
| math |
+------+
| 98.0 |
| 78.0 |
| 98.0 |
| 84.0 |
| 85.0 |
| 73.0 |
| 65.0 |
+------+
--去重查询
select distinct math from exam;
+------+
| math |
+------+
| 98.0 |
| 78.0 |
| 84.0 |
| 85.0 |
| 73.0 |
| 65.0 |
+------+

3.6 排序: order by

语法

-- ASC 为升序(从小到大)
-- DESC 为降序(从大到小)
-- 默认为 ASC
SELECT ... FROM table_name [WHERE ...] ORDER BY column [ASC|DESC], [...];

1.没有 order by 子句的查询,返回的顺序是未定义的,永远不要依赖这个顺序
2.null数据排序,视为比任何值都小,升序出现在最上面,降序出现在最下面

--不加desc, 默认升序排序
select id, name, chinese+math+english as 总分 from exam order by 总分;
+------+-----------+--------+
| id   | name      | 总分   |
+------+-----------+--------+
|    7 | 宋公明    |  170.0 |
|    5 | 刘玄德    |  185.5 |
|    1 | 唐三藏    |  221.0 |
|    6 | 孙权      |  221.5 |
|    4 | 曹孟德    |  233.0 |
|    2 | 孙悟空    |  242.5 |
|    3 | 猪悟能    |  276.0 |
+------+-----------+--------+
--加desc, 降序排序
select id, name, chinese+math+english as 总分 from exam order by 总分 desc;
+------+-----------+--------+
| id   | name      | 总分   |
+------+-----------+--------+
|    3 | 猪悟能    |  276.0 |
|    2 | 孙悟空    |  242.5 |
|    4 | 曹孟德    |  233.0 |
|    6 | 孙权      |  221.5 |
|    1 | 唐三藏    |  221.0 |
|    5 | 刘玄德    |  185.5 |
|    7 | 宋公明    |  170.0 |
+------+-----------+--------+
--多列排序, 分先后
select id, name, chinese, math from exam order by chinese desc, math;
+------+-----------+---------+------+
| id   | name      | chinese | math |
+------+-----------+---------+------+
|    3 | 猪悟能    |    88.0 | 98.0 |
|    2 | 孙悟空    |    87.5 | 78.0 |
|    4 | 曹孟德    |    82.0 | 84.0 |
|    7 | 宋公明    |    75.0 | 65.0 |
|    6 | 孙权      |    70.0 | 73.0 |
|    1 | 唐三藏    |    67.0 | 98.0 |
|    5 | 刘玄德    |    55.5 | 85.0 |
+------+-----------+---------+------+
--先对Chinese进行降序排序, 在不影响原来排序结果的基础上再对math进行升序排序

3.7条件查询

比较运算符:
在这里插入图片描述
逻辑运算符:
在这里插入图片描述
注意:
1.WHERE条件可以使用表达式,但不能使用别名。
2.AND的优先级高于OR,在同时使用时,需要使用小括号()包裹优先执行的部分
示例:

  • 基本查询
-- 查询英语不及格的同学及英语成绩 ( < 60 )
select name, english from exam where english < 60;
+-----------+---------+
| name      | english |
+-----------+---------+
| 唐三藏    |    56.0 |
| 刘玄德    |    45.0 |
| 宋公明    |    30.0 |
+-----------+---------+
-- 查询语文成绩好于英语成绩的同学
select name, chinese, english from exam where chinese > english;
+-----------+---------+---------+
| name      | chinese | english |
+-----------+---------+---------+
| 唐三藏    |    67.0 |    56.0 |
| 孙悟空    |    87.5 |    77.0 |
| 曹孟德    |    82.0 |    67.0 |
| 刘玄德    |    55.5 |    45.0 |
| 宋公明    |    75.0 |    30.0 |
+-----------+---------+---------+
-- 查询总分在 200 分以下的同学
select name, chinese + math + english as 总分 from exam where chinese + math + english < 200;
+-----------+--------+
| name      | 总分   |
+-----------+--------+
| 刘玄德    |  185.5 |
| 宋公明    |  170.0 |
+-----------+--------+
  • and 与 or
-- 查询语文成绩大于80分,且英语成绩大于80分的同学
select * from exam where chinese > 80 and math > 80;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    3 | 猪悟能    |    88.0 | 98.0 |    90.0 |
|    4 | 曹孟德    |    82.0 | 84.0 |    67.0 |
+------+-----------+---------+------+---------+
-- 查询语文成绩大于80分,或英语成绩大于80分的同学
select * from exam where chinese > 80 or math > 80;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    1 | 唐三藏    |    67.0 | 98.0 |    56.0 |
|    2 | 孙悟空    |    87.5 | 78.0 |    77.0 |
|    3 | 猪悟能    |    88.0 | 98.0 |    90.0 |
|    4 | 曹孟德    |    82.0 | 84.0 |    67.0 |
|    5 | 刘玄德    |    55.5 | 85.0 |    45.0 |
+------+-----------+---------+------+---------+
--and的优先级比or高
  • 范围查询
--1. between...and...-- 查询语文成绩在 [80, 90] 分的同学及语文成绩
select name, chinese from exam where chinese between 80 and 90;
-- 使用 AND 也可以实现
select name, chinese from exam where chinese >= 80 and chinese <= 90;
+-----------+---------+
| name      | chinese |
+-----------+---------+
| 孙悟空    |    87.5 |
| 猪悟能    |    88.0 |
| 曹孟德    |    82.0 |
+-----------+---------+--2. in-- 查询数学成绩是 58 或者 59 或者 98 或者 99 分的同学及数学成绩
select name, math from exam where math in (58, 59, 98, 99);
-- 使用 OR 也可以实现
select name, math from exam where math = 58 or math = 59 or math = 98 or math = 99;
+-----------+------+
| name      | math |
+-----------+------+
| 唐三藏    | 98.0 |
| 猪悟能    | 98.0 |
+-----------+------+
  • 模糊查询: like
-- % 匹配任意多个(包括 0 个)字符
select name from exam where name like '孙%';
+-----------+
| name      |
+-----------+
| 孙悟空    |
| 孙权      |
+-----------+
-- _ 匹配严格的一个任意字符
select name from exam where name like '孙_';
+--------+
| name   |
+--------+
| 孙权   |
+--------+
  • NULL的查询: is [not] null
-- 查询 qq_mail 已知的同学姓名
select name, qq_mail from student where qq_mail is not null;-- 查询 qq_mail 未知的同学姓名
select name, qq_mail from student where qq_mail is null;

3.8 分页查询

语法

-- 起始下标为 0
-- 从 0 开始,筛选 n 条结果
SELECT ... FROM table_name [WHERE ...] [ORDER BY ...] LIMIT n;
-- 从 s 开始,筛选 n 条结果
SELECT ... FROM table_name [WHERE ...] [ORDER BY ...] LIMIT s, n;
-- 从 s 开始,筛选 n 条结果,比第二种用法更明确,建议使用
SELECT ... FROM table_name [WHERE ...] [ORDER BY ...] LIMIT n OFFSET s;

分页示例

-- 第 1 页
select * from exam order by id limit 3 offset 0;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    1 | 唐三藏    |    67.0 | 98.0 |    56.0 |
|    2 | 孙悟空    |    87.5 | 78.0 |    77.0 |
|    3 | 猪悟能    |    88.0 | 98.0 |    90.0 |
+------+-----------+---------+------+---------+
-- 第 2 页
select * from exam order by id limit 3 offset 3;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    4 | 曹孟德    |    82.0 | 84.0 |    67.0 |
|    5 | 刘玄德    |    55.5 | 85.0 |    45.0 |
|    6 | 孙权      |    70.0 | 73.0 |    78.5 |
+------+-----------+---------+------+---------+
-- 第 3 页,如果结果不足 3 个,不会有影响
select * from exam order by id limit 3 offset 6;
+------+-----------+---------+------+---------+
| id   | name      | chinese | math | english |
+------+-----------+---------+------+---------+
|    7 | 宋公明    |    75.0 | 65.0 |    30.0 |
+------+-----------+---------+------+---------+

4. 修改 (update)

语法

UPDATE table_name SET column = expr [, column = expr ...][WHERE ...] [ORDER BY ...] [LIMIT ...]

案例

-- 将孙悟空同学的数学成绩变更为 80 分
update exam set math = 80 where name = '孙悟空';-- 将曹孟德同学的数学成绩变更为 60 分,语文成绩变更为 70 分
update exam set math = 60, chinese = 70 where name = '曹孟德';-- 将总成绩倒数前三的 3 位同学的数学成绩加上 30 分
update exam set math = math + 30 order by chinese + math + english limit 3;-- 将所有同学的语文成绩更新为原来的 2 倍
update exam set chinese = chinese * 2;

5. 删除(delete)

语法

DELETE FROM  table_name [WHERE ...] [ORDER BY ...] [LIMIT ...]

案例

-- 删除孙悟空同学的考试成绩
delete from exam where name = '孙悟空';-- 删除整表数据
delete from exam;

6. 内容重点总结

  • 新增
-- 单行插入
insert into(字段1, ..., 字段N) values (value1, ..., value N);
-- 多行插入
insert into(字段1, ..., 字段N) values
(value1, ...),
(value2, ...),
(value3, ...);
  • 查询
-- 全列查询
select * from-- 指定列查询
select 字段1,字段2... from-- 查询表达式字段
select 字段1+100,字段2+字段3 from-- 别名
select 字段1 别名1, 字段2 别名2 from-- 去重DISTINCT
select distinct 字段 from-- 排序ORDER BY
select * fromorder by 排序字段
-- 条件查询WHERE:
-- (1)比较运算符 (2)BETWEEN ... AND ... (3)IN (4)IS NULL (5)LIKE (6)AND (7)OR 
(8)NOT
select * fromwhere 条件
  • 修改
updateset 字段1=value1, 字段2=value2... where 条件
  • 删除
delete fromwhere 条件
http://www.dinnco.com/news/4316.html

相关文章:

  • 中国工程造价信息网官网新十条优化措施
  • 网站注册好域名怎么办seo网站系统
  • 甘肃省人民政府门户网seo排名优化资源
  • 做7寸照片的网站如何做好营销推广
  • 宁海哪家做网站比较可靠企业营销策划方案
  • WordPress全球用户量2019长沙网站包年优化
  • 东营做网站哪里好关键词歌词完整版
  • 风景旅游网站建设的设计思路网络营销主要有哪些特点
  • 聊城哪里有做网站的新品牌推广策划方案
  • 网站后台会员管理网上推广怎么收费
  • 建立销售型网站武汉网站设计公司
  • 做日本ppt的模板下载网站有哪些seo网站优化技术
  • 上海好的高端网站建设服务公司头条搜索是百度引擎吗
  • 东莞网页设计培训学校北京关键词优化平台
  • wordpress hashone山东济南seo整站优化费用
  • 建设银行网站点不进去推广赚钱的平台
  • 国外网站页面做多大付费推广有几种方式
  • 云游戏网站在线玩弹窗广告最多的网站
  • 模型下载网站开发流程短信广告投放
  • 南京网站推广营销公司哪家好南宁百度seo排名价格
  • 网站建设 工作室网络防御中心
  • 网站后台 模板网站模板下载免费
  • 论文引用网站数据 如何做注释友情链接交换的作用在于
  • 深圳市政府网站建设 网站管理天津百度推广公司地址
  • 网站备案号被注销什么原因网店seo排名优化
  • java语言做网站全网引擎搜索
  • 网站推广做招商加盟google在线代理
  • 做个购物商城网站多长时间2023年小学生简短小新闻
  • 毕设做网站可以用模板吗全网营销系统是干什么的
  • 山东省城乡建设厅网站seo零基础视频教程