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

拿p5.js做的网站互联网平台

拿p5.js做的网站,互联网平台,宣城公司做网站,在线代码编辑器文章目录 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.tj-hxxt.cn/news/80146.html

相关文章:

  • 旅游网站的网页设计互联网搜索引擎有哪些
  • 怎么用wordpress建立自己的网站吗百度竞价在哪里开户
  • 做黄色网站赚钱么厦门seo网站推广
  • 增城企业网站建设网站推广优化业务
  • asp net网站建设百度站长工具添加不了站点
  • to a wordpressseo自学网免费
  • 如何做网站的优化和推广公众号软文推广多少钱一篇
  • 广东东莞自己建站教程百度霸屏推广靠谱吗
  • 购物网站底部设计网店代运营商
  • 手机网站可以做商城吗百度网站域名
  • flash网站规划网站自动秒收录工具
  • 四川今日发布最新新冠疫情牛排seo系统
  • 苏州网站建设哪家好软文网
  • 海口专业网站搭建批发网页做推广
  • albatros wordpress站长工具seo综合查询
  • 深圳做夜场做网站网站推广开户
  • 400电话安装佛山营销网站建设手游推广平台有哪些
  • 成都企业建站系统武汉seo首页优化技巧
  • 做app页面的网站汕头网络营销公司
  • 企业商城网站多少钱网站seo在线诊断分析
  • 学建网站网络营销工作内容和职责
  • 西宁网站建设公司排行免费seo网站优化工具
  • 做网站代理去拉人微信小程序怎么做店铺
  • 跟老外做网站口碑营销是什么意思
  • 深圳网站建设伪静态 报价 jsp 语言营销qq
  • 可以做录音兼职的网站个人发布信息免费推广平台
  • 私人定制哪个网站做的比较好做公司网站需要多少钱
  • 深圳搭建网站公司网络营销师证书需要多少钱
  • 南阳市住房和城市建设局网站向日葵seo
  • 花卉网站源码西安企业做网站