个人备案网站可以做商城吗wordpress表单 post
个人备案网站可以做商城吗,wordpress表单 post,论坛类网站建设,网站增值业务一.SQL语言1.全称#xff1a;结构化查询语言2.分类1.DDL 数据定义语言1.作用#xff1a;①定义数据库②定义数据表③定义字段2.关键字#xff1a;①creat②drop③alter2.DML 数据操作语言1.作用#xff1a;操作数据表的结构2.关键字#xff1a;①insert into②delete③u…一.SQL语言1.全称结构化查询语言2.分类1.DDL 数据定义语言1.作用①定义数据库②定义数据表③定义字段2.关键字①creat②drop③alter2.DML 数据操作语言1.作用操作数据表的结构2.关键字①insert into②delete③update3.DQL 数据查询语言1.作用查询表中的数据2.关键字①select②from③where4.DCL 数据控制语言3.通用规则1.每条SQL语句以; 结尾2.SQL语句可以使用空格和换行格式化展示3.注释1.单行注释①#注释内容②--注释内容2.多行注释/*多行*/二.MySQL数据库1.安装数据库2.连接数据库①命令mysql -h主机地址 -P端口号 -u用户名 -p密码②工具3.DDL①创建数据库create database [if not exists] 库名;# TODO 1.数据库的创建和查看 -- 创建数据库test1 CREATE DATABASE test1; -- IF NOT EXISTS: 如果存在就忽略,不存在就创建 CREATE DATABASE IF NOT EXISTS test2; CREATE DATABASE IF NOT EXISTS test3; -- use 库名: 切换数据库 USE test3; -- 查看所有数据库 SHOW DATABASES; # TODO 2.库中表的创建和查看 # 前题: 先创建并使用库 # 创建数据库 CREATE DATABASE my_db; USE my_db;②创建表(含字段)create table [if not exists] 表名(字段名 字段类型 [字段约束] ,...);# 创建学生表 CREATE TABLE student ( name varchar(30), age int ); # 创建教师表 CREATE TABLE teacher ( name varchar(30), age int );4.DML①插入数据insert into 表名(字段名...) values(字段值...);# 先创建taobao_db库 create database taobao_db; # 再创建users表 create table taobao_db.users( id int , name varchar(30), phone bigint ); # 最后插入数据 insert into taobao_db.users(id,name,phone) values(1,张三,18866669999); insert into taobao_db.users(id,name,phone) values(1,张三,18866669999),(2,李四,16677778888); # 注意: 不指定字段,默认等于指定了所有字段 insert into taobao_db.users values(1,张三,18866669999); insert into taobao_db.users values(1,张三,18866669999),(2,李四,16677778888); insert into taobao_db.users(name) values(王五);②更新数据update 表名 set 字段名 新值 [where 条件];# 演示如何修改数据 update taobao_db.users set phone 17788889999 where name 李四; # 注意: 如果忘记了添加where条件,就变成了修改所有 update taobao_db.users set phone 17788889999;③删除数据delete from 表名 [where 条件] ;# 演示如何删除数据 delete from taobao_db.users where name 张三; # 注意: 如果忘记了添加where条件,就变成删除所有 delete from taobao_db.users ; # 演示truncate删除数据(如果真的有清空数据需求,建议用truancate) # 因为上面delete已经删除干净了,再次插入数据用于删除 insert into taobao_db.users(name) values(张三),(李四),(王五); truncate table taobao_db.users;5.DQL1.基础查询select 字段名 from 表名;# 创建数据库: create database 库名; CREATE DATABASE IF NOT EXISTS tb_db CHARSETutf8; # 使用数据库: use 库名; USE tb_db; # 创建表: create table 表名(字段名 字段类型 [约束],...); # 建测试表 drop table if EXISTS products; CREATE TABLE IF NOT EXISTS products ( id INT PRIMARY KEY AUTO_INCREMENT, -- 商品ID name VARCHAR(24) NOT NULL, -- 商品名称 price DECIMAL(10, 2) NOT NULL, -- 商品价格 score DECIMAL(5, 2), -- 商品评分可以为空 is_self VARCHAR(8), -- 是否自营 category_id INT -- 商品类别ID ); drop table if EXISTS category; CREATE TABLE IF NOT EXISTS category ( id INT PRIMARY KEY AUTO_INCREMENT, -- 商品类别ID name VARCHAR(24) NOT NULL -- 类别名称 ); # 插入数据: insert into 表名 (字段名,字段名) values(字段值,字段值),(字段值,字段值); # 添加测试数据 INSERT INTO category VALUES (1, 手机), (2, 电脑), (3, 美妆), (4, 家居); INSERT INTO products VALUES (1, 华为Mate50, 5499.00, 9.70, 自营, 1), (2, 荣耀80, 2399.00, 9.50, 自营, 1), (3, 荣耀80, 2199.00, 9.30, 非自营, 1), (4, 红米note 11, 999.00, 9.00, 非自营, 1), (5, 联想小新14, 4199.00, 9.20, 自营, 2), (6, 惠普战66, 4499.90, 9.30, 自营, 2), (7, 苹果Air13, 6198.00, 9.10, 非自营, 2), (8, 华为MateBook14, 5599.00, 9.30, 非自营, 2), (9, 兰蔻小黑瓶, 1100.00, 9.60, 自营, 3), (10, 雅诗兰黛粉底液, 920.00, 9.40, 自营, 3), (11, 阿玛尼红管405, 350.00, NULL, 非自营, 3), (12, 迪奥996, 330.00, 9.70, 非自营, 3); # 查看自增效果 insert into category(name) values(食品); insert into products(name,price) values(辣条,0.5); # 1.基础查询 # 需求: 查询所有信息 select * from products; # 需求: 查询商品的名称和价格 select name,price from products; # 给名称和价格起别名展示 select name as n,price as p from products; select name as 名称,price as 价格 from products; # 需求: 查询商品的类别编号有哪些 select DISTINCT category_id from products;2.条件查询select 字段名 from 表名 where 条件;# 需求: 查询价格大于4199并且小于6000的商品信息 select * from products where price 4199 and price 6000; # 需求: 查询价格不等于4199的商品信息 select * from products where price ! 4199; select * from products where price 4199; # 需求: 查询价格是4199 或 4499 的商品信息 select * from products where price 4199 or price 4499.9; select * from products where price in (4199,4499.9); # 需求: 查询价格大于等于4199并且小于等于6000的商品信息 select * from products where price 4199 and price 6000; select * from products where price BETWEEN 4199 and 6000; # 需求: 查询价格不在4199-6000之间的商品信息 select * from products where price 4199 or price 6000; select * from products where not (price 4199 and price 6000); select * from products where price not BETWEEN 4199 and 6000; # 需求: 查询商品名称以华开头的商品信息 select * from products where name like 华%; # 需求: 查询商品名称第三个字是小的商品信息 select * from products where name like __小%; # 需求: 查询商品名称中带兰字的商品信息 select * from products where name like %兰%; # 需求: 查询已经评分的商品信息 select * from products where score is not null; # 需求: 查询未评分的商品信息 select * from products where score is null;1.比较运算符 ! 2.逻辑运算符and or not3.范围查询①between x and y②in(x,y)4.模糊查询1.关键字like2.符号①%: 任意0个或者多个字符②_ :任意1个字符5.非空判断①is null②is not null3.聚合查询select 聚合函数(字段名) from 表名;# 需求: 查询商品的价格总和,平均值,最大值,最小值 select sum(price),avg(price),max(price),min(price) from products; # 需求: 查询所有商品个数 select count(*) from products; # 推荐 select count(id) from products; # 需求: 查询已评分的商品个数 select count(*) from products where score is not null; # 需求: 查询已评分的商品平均价格 select avg(price) from products where score is not null;4.分组查询select 分组字段名,聚合函数(字段名) from 表名 [where 非聚合条件] group by 分组字段名 [having 聚合条件];# 需求: 查询商品的价格总和,平均值,最大值,最小值 select sum(price),avg(price),max(price),min(price) from products; # 需求: 查询所有商品个数 select count(*) from products; # 推荐 select count(id) from products; # 需求: 查询已评分的商品个数 select count(*) from products where score is not null; # 需求: 查询已评分的商品平均价格 select avg(price) from products where score is not null; # 5.分组查询 # 需求: 查询商品表中的分类id select DISTINCT category_id from products; select category_id from products group by category_id; # 需求: 查询每个分类中商品平均价格 # 笨方式 select 1,avg(price) from products where category_id 1; select 2,avg(price) from products where category_id 2; select 3,avg(price) from products where category_id 3; select null,avg(price) from products where category_id is null; # group by方式 select category_id,avg(price) from products group by category_id; # 以下代码在mysql老版本中能够正常使用但是没有意义,新版本中因为底层设置了sql_modeonly_full_group_by,让它报错 select name,avg(price) from products group by category_id; select sql_mode; # set SQL_MODE STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION;5.排序查询select 字段名 from 表名 where 条件 order by 排序字段名 asc | desc;# 需求: 按照评分升序排序 select * from products order by score asc; # 因为默认升序,此处警告是说多余的 select * from products order by score ; # 需求: 按照评分降序排序 select * from products order by score desc; # 需求: 先按照评分降序排序,然后按照价格降序排序 select * from products order by score desc,price desc;6.limit查询select 字段名 from 表名 where 条件 order by 排序字段名 asc | desc limit x,y;# topn需求 # 需求: 查询价格最高的商品信息 select * from products order by price desc limit 1; # 需求: 查询价格最高的5个商品信息 select * from products order by price desc limit 0,5; # 分页需求 # 假设每页展示4条数据要求获取每页的数据 # 第1页 select * from products limit 0,4; # 第2页 select * from products limit 4,4; # 第3页 select * from products limit 8,4; # 第4页 select * from products limit 12,4; # 结论limit x,y: x(页数-1)*y7.SQL顺序①书写顺序select - 聚合函数 - from - where - group by - having -order by - limit②执行顺序from - where - group by - 聚合函数 - having - select - order by - limit8.多表查询本质就是先把多个表连接(join)成一个表,再去查询