![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
mysql
Deltadawn
这个作者很懒,什么都没留下…
展开
-
mysql day12 索引
explain select customer_id from customers where state = 'CA'; select count(*) from customers; create index idx_state on customers (state);-- 减少查询次数a explain select customer_id from customers where points >= 1000; create index idx_points on customers (p原创 2021-11-14 10:45:39 · 850 阅读 · 0 评论 -
mysql day13 表
create database if not exists sql_store2; -- 如果先前没有才创建 use sql_store2; drop table if exists orders; -- 此时可删,重新创建 drop table if exists customers; -- 此时不能删除顾客表,因为orders依赖于customers;要删除顾客表,需要先删除订单表,放在上边 create table if not exists customers ( customer_id in.原创 2021-11-13 11:32:23 · 843 阅读 · 0 评论 -
mysql day11 第十二章数据类型(部分)
-- 第十二章 数据类型 -- 字符串类型 -- char 固定长度,州的缩写 -- varchar 可变长度,最大是65535 用户名密码-varchar(50);varchar(255)地址 -- mediumtext 最大为16mb -- longtext 最大为4GB -- 英文字母1B,中文3B -- bool类型 -- boolean -- 枚举类型和集合 -- json类型,可存储多个健值对alter -- update products -- set properties = ' -- {原创 2021-11-12 09:49:53 · 87 阅读 · 0 评论 -
mysql day10 第十一章事务
-- 第十一章 事务 -- use sql_store; -- start transaction; -- insert into orders(customer_id,order_date,status) -- values(1,'2019-01-01',1); -- insert into order_items -- values(last_insert_id(),1,1,1); -- -- last_insert_id()会返回最新插入订单的id -- commit; -- 事务结原创 2021-11-11 12:39:39 · 529 阅读 · 0 评论 -
mysql day9 第十章 事件
-- 第十章 触发器 -- delimiter $$ -- create trigger payments_after_insert -- 表名_after/before_insert/delete/update -- after insert on payments -- insert/delete/update -- for each row -- 每行都会触发 -- -- 可以修改任何表中的数据,除了这个触发器所在表 -- begin -- -- 触发的主体部分 -- up原创 2021-11-10 13:16:32 · 533 阅读 · 0 评论 -
mysql day8 第九章 存储过程
-- 第九章 存储过程 -- 存储过程中的每条语句都要用分号终止,改动默认分隔符 -- delimiter $$ -- create procedure get_clients() -- begin -- select * from clients; -- end$$ -- delimiter ; -- call get_clients() -- 返回数据库中的所有客户 delimiter $$ create procedure get_invoice_with_balance() begin s原创 2021-11-09 16:52:13 · 395 阅读 · 0 评论 -
mysql day7 第八章 创建视图
-- 第八章 1-创建视图 -- 视图不存储数据,数据存在表中 -- use sql_invoicing; -- create view sales_by_client as -- select -- c.client_id, -- c.name, -- sum(invoice_total) as total_sale -- from clients c -- join invoices i using (client_id) -- group by client_id,name -- 习题原创 2021-11-07 11:27:33 · 92 阅读 · 0 评论 -
mysql day6 第七章数值函数
-- 第七章 数值函数 -- select round(5.7345,2); -- 5.73 -- select truncate(5.7345,3); -- 5.734 截断,只保留前三位 -- select ceiling(5.7); -- 6 ,5.2也得6 返回大于或等于这个数字的最小整数 -- select floor(5.2); -- 5 返回小于或等于这个数字的最大整数 -- select abs(-5.2); -- 5.2 绝对值 -- select rand(); -- 0-1之间的随机值原创 2021-11-07 11:25:26 · 72 阅读 · 0 评论 -
mysql day5 编写复杂查询
-- select * -- from products -- where unit_price > ( -- select unit_price -- from products -- where product_id = 3) -- 习题 在平均收入以伤害 -- use sql_hr; -- select * -- from employees -- where salary > ( -- select AVG(salary) -- from employees --原创 2021-11-06 11:58:19 · 82 阅读 · 0 评论 -
mysql day4
– 聚合函数,只运行非空树枝 – 汇总数据 – MAX() – MIN() – AVG() – SUM() – COUNT() – count(invoice_total) as number_of_invoices,-- 返回非空 – count(payment_date) as count_of_payments, – select – max(invoice_total) as highest, – min(invoice_total) as lowest, –原创 2021-11-05 16:45:46 · 87 阅读 · 0 评论 -
mysql day3
– 插入 – default:系统自动生成唯一值,第一列为主键不需要增加,系统自动递增,直接从第二列开始 – insert into customers – values ( – default, – ‘John’, – ‘Smith’, – ‘1990-01-01’, – null,这行可空 – null, – default 与 null结果相同 – ‘address’, – ‘city’, – ‘CA’, – default) –原创 2021-11-05 16:44:33 · 74 阅读 · 0 评论 -
mysql day2
– 自链接 – use sql_hr; – select e.employee_id, e.first_name, m.first_name as manager – 得出每个员工的编号姓名和对应管理者的姓名 – from employees e – join employees m – on e.reports_to = m.employee_id – 多表链接 – use sql_store; – select – o.order_id, – 订单id – o.order_date,原创 2021-11-02 13:07:34 · 80 阅读 · 0 评论 -
mysqlworkbench day1
USE sql_store; //只查询一个文件下的表或者双击选择数据库,不然没显示 SELECT *//返回所有列 FROM customers//查询的是文件下customers的表的所有列,可以直接接到select后 – WHERE customer_id = 1//查询id为1的顾客,只显示一条记录 – ORDER BY first_name//按照firstname排序 SELECT last_name, first_name, points, (points+10)*100 //注意算数表达式的原创 2021-11-01 20:06:02 · 127 阅读 · 0 评论