主頁 > 資料庫 > sql資料庫語言練習,增刪改查

sql資料庫語言練習,增刪改查

2020-09-19 09:12:57 資料庫

資料庫創建

DROP DATABASE IF EXISTS `sql_invoicing`;
CREATE DATABASE `sql_invoicing`; 
USE `sql_invoicing`;

SET NAMES utf8 ;
SET character_set_client = utf8mb4 ;

CREATE TABLE `payment_methods` (
  `payment_method_id` tinyint(4) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`payment_method_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `payment_methods` VALUES (1,'Credit Card');
INSERT INTO `payment_methods` VALUES (2,'Cash');
INSERT INTO `payment_methods` VALUES (3,'PayPal');
INSERT INTO `payment_methods` VALUES (4,'Wire Transfer');

CREATE TABLE `clients` (
  `client_id` int(11) NOT NULL,
  `name` varchar(50) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `state` char(2) NOT NULL,
  `phone` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `clients` VALUES (1,'Vinte','3 Nevada Parkway','Syracuse','NY','315-252-7305');
INSERT INTO `clients` VALUES (2,'Myworks','34267 Glendale Parkway','Huntington','WV','304-659-1170');
INSERT INTO `clients` VALUES (3,'Yadel','096 Pawling Parkway','San Francisco','CA','415-144-6037');
INSERT INTO `clients` VALUES (4,'Kwideo','81674 Westerfield Circle','Waco','TX','254-750-0784');
INSERT INTO `clients` VALUES (5,'Topiclounge','0863 Farmco Road','Portland','OR','971-888-9129');

CREATE TABLE `invoices` (
  `invoice_id` int(11) NOT NULL,
  `number` varchar(50) NOT NULL,
  `client_id` int(11) NOT NULL,
  `invoice_total` decimal(9,2) NOT NULL,
  `payment_total` decimal(9,2) NOT NULL DEFAULT '0.00',
  `invoice_date` date NOT NULL,
  `due_date` date NOT NULL,
  `payment_date` date DEFAULT NULL,
  PRIMARY KEY (`invoice_id`),
  KEY `FK_client_id` (`client_id`),
  CONSTRAINT `FK_client_id` FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `invoices` VALUES (1,'91-953-3396',2,101.79,0.00,'2019-03-09','2019-03-29',NULL);
INSERT INTO `invoices` VALUES (2,'03-898-6735',5,175.32,8.18,'2019-06-11','2019-07-01','2019-02-12');
INSERT INTO `invoices` VALUES (3,'20-228-0335',5,147.99,0.00,'2019-07-31','2019-08-20',NULL);
INSERT INTO `invoices` VALUES (4,'56-934-0748',3,152.21,0.00,'2019-03-08','2019-03-28',NULL);
INSERT INTO `invoices` VALUES (5,'87-052-3121',5,169.36,0.00,'2019-07-18','2019-08-07',NULL);
INSERT INTO `invoices` VALUES (6,'75-587-6626',1,157.78,74.55,'2019-01-29','2019-02-18','2019-01-03');
INSERT INTO `invoices` VALUES (7,'68-093-9863',3,133.87,0.00,'2019-09-04','2019-09-24',NULL);
INSERT INTO `invoices` VALUES (8,'78-145-1093',1,189.12,0.00,'2019-05-20','2019-06-09',NULL);
INSERT INTO `invoices` VALUES (9,'77-593-0081',5,172.17,0.00,'2019-07-09','2019-07-29',NULL);
INSERT INTO `invoices` VALUES (10,'48-266-1517',1,159.50,0.00,'2019-06-30','2019-07-20',NULL);
INSERT INTO `invoices` VALUES (11,'20-848-0181',3,126.15,0.03,'2019-01-07','2019-01-27','2019-01-11');
INSERT INTO `invoices` VALUES (13,'41-666-1035',5,135.01,87.44,'2019-06-25','2019-07-15','2019-01-26');
INSERT INTO `invoices` VALUES (15,'55-105-9605',3,167.29,80.31,'2019-11-25','2019-12-15','2019-01-15');
INSERT INTO `invoices` VALUES (16,'10-451-8824',1,162.02,0.00,'2019-03-30','2019-04-19',NULL);
INSERT INTO `invoices` VALUES (17,'33-615-4694',3,126.38,68.10,'2019-07-30','2019-08-19','2019-01-15');
INSERT INTO `invoices` VALUES (18,'52-269-9803',5,180.17,42.77,'2019-05-23','2019-06-12','2019-01-08');
INSERT INTO `invoices` VALUES (19,'83-559-4105',1,134.47,0.00,'2019-11-23','2019-12-13',NULL);

CREATE TABLE `payments` (
  `payment_id` int(11) NOT NULL AUTO_INCREMENT,
  `client_id` int(11) NOT NULL,
  `invoice_id` int(11) NOT NULL,
  `date` date NOT NULL,
  `amount` decimal(9,2) NOT NULL,
  `payment_method` tinyint(4) NOT NULL,
  PRIMARY KEY (`payment_id`),
  KEY `fk_client_id_idx` (`client_id`),
  KEY `fk_invoice_id_idx` (`invoice_id`),
  KEY `fk_payment_payment_method_idx` (`payment_method`),
  CONSTRAINT `fk_payment_client` FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_payment_invoice` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`invoice_id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_payment_payment_method` FOREIGN KEY (`payment_method`) REFERENCES `payment_methods` (`payment_method_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `payments` VALUES (1,5,2,'2019-02-12',8.18,1);
INSERT INTO `payments` VALUES (2,1,6,'2019-01-03',74.55,1);
INSERT INTO `payments` VALUES (3,3,11,'2019-01-11',0.03,1);
INSERT INTO `payments` VALUES (4,5,13,'2019-01-26',87.44,1);
INSERT INTO `payments` VALUES (5,3,15,'2019-01-15',80.31,1);
INSERT INTO `payments` VALUES (6,3,17,'2019-01-15',68.10,1);
INSERT INTO `payments` VALUES (7,5,18,'2019-01-08',32.77,1);
INSERT INTO `payments` VALUES (8,5,18,'2019-01-08',10.00,2);


DROP DATABASE IF EXISTS `sql_store`;
CREATE DATABASE `sql_store`;
USE `sql_store`;

CREATE TABLE `products` (
  `product_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `quantity_in_stock` int(11) NOT NULL,
  `unit_price` decimal(4,2) NOT NULL,
  PRIMARY KEY (`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `products` VALUES (1,'Foam Dinner Plate',70,1.21);
INSERT INTO `products` VALUES (2,'Pork - Bacon,back Peameal',49,4.65);
INSERT INTO `products` VALUES (3,'Lettuce - Romaine, Heart',38,3.35);
INSERT INTO `products` VALUES (4,'Brocolinni - Gaylan, Chinese',90,4.53);
INSERT INTO `products` VALUES (5,'Sauce - Ranch Dressing',94,1.63);
INSERT INTO `products` VALUES (6,'Petit Baguette',14,2.39);
INSERT INTO `products` VALUES (7,'Sweet Pea Sprouts',98,3.29);
INSERT INTO `products` VALUES (8,'Island Oasis - Raspberry',26,0.74);
INSERT INTO `products` VALUES (9,'Longan',67,2.26);
INSERT INTO `products` VALUES (10,'Broom - Push',6,1.09);


CREATE TABLE `shippers` (
  `shipper_id` smallint(6) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`shipper_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `shippers` VALUES (1,'Hettinger LLC');
INSERT INTO `shippers` VALUES (2,'Schinner-Predovic');
INSERT INTO `shippers` VALUES (3,'Satterfield LLC');
INSERT INTO `shippers` VALUES (4,'Mraz, Renner and Nolan');
INSERT INTO `shippers` VALUES (5,'Waters, Mayert and Prohaska');


CREATE TABLE `customers` (
  `customer_id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(50) NOT NULL,
  `last_name` varchar(50) NOT NULL,
  `birth_date` date DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `state` char(2) NOT NULL,
  `points` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `customers` VALUES (1,'Babara','MacCaffrey','1986-03-28','781-932-9754','0 Sage Terrace','Waltham','MA',2273);
INSERT INTO `customers` VALUES (2,'Ines','Brushfield','1986-04-13','804-427-9456','14187 Commercial Trail','Hampton','VA',947);
INSERT INTO `customers` VALUES (3,'Freddi','Boagey','1985-02-07','719-724-7869','251 Springs Junction','Colorado Springs','CO',2967);
INSERT INTO `customers` VALUES (4,'Ambur','Roseburgh','1974-04-14','407-231-8017','30 Arapahoe Terrace','Orlando','FL',457);
INSERT INTO `customers` VALUES (5,'Clemmie','Betchley','1973-11-07',NULL,'5 Spohn Circle','Arlington','TX',3675);
INSERT INTO `customers` VALUES (6,'Elka','Twiddell','1991-09-04','312-480-8498','7 Manley Drive','Chicago','IL',3073);
INSERT INTO `customers` VALUES (7,'Ilene','Dowson','1964-08-30','615-641-4759','50 Lillian Crossing','Nashville','TN',1672);
INSERT INTO `customers` VALUES (8,'Thacher','Naseby','1993-07-17','941-527-3977','538 Mosinee Center','Sarasota','FL',205);
INSERT INTO `customers` VALUES (9,'Romola','Rumgay','1992-05-23','559-181-3744','3520 Ohio Trail','Visalia','CA',1486);
INSERT INTO `customers` VALUES (10,'Levy','Mynett','1969-10-13','404-246-3370','68 Lawn Avenue','Atlanta','GA',796);


CREATE TABLE `order_statuses` (
  `order_status_id` tinyint(4) NOT NULL,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`order_status_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `order_statuses` VALUES (1,'Processed');
INSERT INTO `order_statuses` VALUES (2,'Shipped');
INSERT INTO `order_statuses` VALUES (3,'Delivered');


CREATE TABLE `orders` (
  `order_id` int(11) NOT NULL AUTO_INCREMENT,
  `customer_id` int(11) NOT NULL,
  `order_date` date NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT '1',
  `comments` varchar(2000) DEFAULT NULL,
  `shipped_date` date DEFAULT NULL,
  `shipper_id` smallint(6) DEFAULT NULL,
  PRIMARY KEY (`order_id`),
  KEY `fk_orders_customers_idx` (`customer_id`),
  KEY `fk_orders_shippers_idx` (`shipper_id`),
  KEY `fk_orders_order_statuses_idx` (`status`),
  CONSTRAINT `fk_orders_customers` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_orders_order_statuses` FOREIGN KEY (`status`) REFERENCES `order_statuses` (`order_status_id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_orders_shippers` FOREIGN KEY (`shipper_id`) REFERENCES `shippers` (`shipper_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `orders` VALUES (1,6,'2019-01-30',1,NULL,NULL,NULL);
INSERT INTO `orders` VALUES (2,7,'2018-08-02',2,NULL,'2018-08-03',4);
INSERT INTO `orders` VALUES (3,8,'2017-12-01',1,NULL,NULL,NULL);
INSERT INTO `orders` VALUES (4,2,'2017-01-22',1,NULL,NULL,NULL);
INSERT INTO `orders` VALUES (5,5,'2017-08-25',2,'','2017-08-26',3);
INSERT INTO `orders` VALUES (6,10,'2018-11-18',1,'Aliquam erat volutpat. In congue.',NULL,NULL);
INSERT INTO `orders` VALUES (7,2,'2018-09-22',2,NULL,'2018-09-23',4);
INSERT INTO `orders` VALUES (8,5,'2018-06-08',1,'Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis.',NULL,NULL);
INSERT INTO `orders` VALUES (9,10,'2017-07-05',2,'Nulla mollis molestie lorem. Quisque ut erat.','2017-07-06',1);
INSERT INTO `orders` VALUES (10,6,'2018-04-22',2,NULL,'2018-04-23',2);


CREATE TABLE `order_items` (
  `order_id` int(11) NOT NULL AUTO_INCREMENT,
  `product_id` int(11) NOT NULL,
  `quantity` int(11) NOT NULL,
  `unit_price` decimal(4,2) NOT NULL,
  PRIMARY KEY (`order_id`,`product_id`),
  KEY `fk_order_items_products_idx` (`product_id`),
  CONSTRAINT `fk_order_items_orders` FOREIGN KEY (`order_id`) REFERENCES `orders` (`order_id`) ON UPDATE CASCADE,
  CONSTRAINT `fk_order_items_products` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `order_items` VALUES (1,4,4,3.74);
INSERT INTO `order_items` VALUES (2,1,2,9.10);
INSERT INTO `order_items` VALUES (2,4,4,1.66);
INSERT INTO `order_items` VALUES (2,6,2,2.94);
INSERT INTO `order_items` VALUES (3,3,10,9.12);
INSERT INTO `order_items` VALUES (4,3,7,6.99);
INSERT INTO `order_items` VALUES (4,10,7,6.40);
INSERT INTO `order_items` VALUES (5,2,3,9.89);
INSERT INTO `order_items` VALUES (6,1,4,8.65);
INSERT INTO `order_items` VALUES (6,2,4,3.28);
INSERT INTO `order_items` VALUES (6,3,4,7.46);
INSERT INTO `order_items` VALUES (6,5,1,3.45);
INSERT INTO `order_items` VALUES (7,3,7,9.17);
INSERT INTO `order_items` VALUES (8,5,2,6.94);
INSERT INTO `order_items` VALUES (8,8,2,8.59);
INSERT INTO `order_items` VALUES (9,6,5,7.28);
INSERT INTO `order_items` VALUES (10,1,10,6.01);
INSERT INTO `order_items` VALUES (10,9,9,4.28);

CREATE TABLE `sql_store`.`order_item_notes` (
  `note_id` INT NOT NULL,
  `order_Id` INT NOT NULL,
  `product_id` INT NOT NULL,
  `note` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`note_id`));

INSERT INTO `order_item_notes` (`note_id`, `order_Id`, `product_id`, `note`) VALUES ('1', '1', '2', 'first note');
INSERT INTO `order_item_notes` (`note_id`, `order_Id`, `product_id`, `note`) VALUES ('2', '1', '2', 'second note');


DROP DATABASE IF EXISTS `sql_hr`;
CREATE DATABASE `sql_hr`;
USE `sql_hr`;


CREATE TABLE `offices` (
  `office_id` int(11) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `state` varchar(50) NOT NULL,
  PRIMARY KEY (`office_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `offices` VALUES (1,'03 Reinke Trail','Cincinnati','OH');
INSERT INTO `offices` VALUES (2,'5507 Becker Terrace','New York City','NY');
INSERT INTO `offices` VALUES (3,'54 Northland Court','Richmond','VA');
INSERT INTO `offices` VALUES (4,'08 South Crossing','Cincinnati','OH');
INSERT INTO `offices` VALUES (5,'553 Maple Drive','Minneapolis','MN');
INSERT INTO `offices` VALUES (6,'23 North Plaza','Aurora','CO');
INSERT INTO `offices` VALUES (7,'9658 Wayridge Court','Boise','ID');
INSERT INTO `offices` VALUES (8,'9 Grayhawk Trail','New York City','NY');
INSERT INTO `offices` VALUES (9,'16862 Westend Hill','Knoxville','TN');
INSERT INTO `offices` VALUES (10,'4 Bluestem Parkway','Savannah','GA');



CREATE TABLE `employees` (
  `employee_id` int(11) NOT NULL,
  `first_name` varchar(50) NOT NULL,
  `last_name` varchar(50) NOT NULL,
  `job_title` varchar(50) NOT NULL,
  `salary` int(11) NOT NULL,
  `reports_to` int(11) DEFAULT NULL,
  `office_id` int(11) NOT NULL,
  PRIMARY KEY (`employee_id`),
  KEY `fk_employees_offices_idx` (`office_id`),
  KEY `fk_employees_employees_idx` (`reports_to`),
  CONSTRAINT `fk_employees_managers` FOREIGN KEY (`reports_to`) REFERENCES `employees` (`employee_id`),
  CONSTRAINT `fk_employees_offices` FOREIGN KEY (`office_id`) REFERENCES `offices` (`office_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `employees` VALUES (37270,'Yovonnda','Magrannell','Executive Secretary',63996,NULL,10);
INSERT INTO `employees` VALUES (33391,'D\'arcy','Nortunen','Account Executive',62871,37270,1);
INSERT INTO `employees` VALUES (37851,'Sayer','Matterson','Statistician III',98926,37270,1);
INSERT INTO `employees` VALUES (40448,'Mindy','Crissil','Staff Scientist',94860,37270,1);
INSERT INTO `employees` VALUES (56274,'Keriann','Alloisi','VP Marketing',110150,37270,1);
INSERT INTO `employees` VALUES (63196,'Alaster','Scutchin','Assistant Professor',32179,37270,2);
INSERT INTO `employees` VALUES (67009,'North','de Clerc','VP Product Management',114257,37270,2);
INSERT INTO `employees` VALUES (67370,'Elladine','Rising','Social Worker',96767,37270,2);
INSERT INTO `employees` VALUES (68249,'Nisse','Voysey','Financial Advisor',52832,37270,2);
INSERT INTO `employees` VALUES (72540,'Guthrey','Iacopetti','Office Assistant I',117690,37270,3);
INSERT INTO `employees` VALUES (72913,'Kass','Hefferan','Computer Systems Analyst IV',96401,37270,3);
INSERT INTO `employees` VALUES (75900,'Virge','Goodrum','Information Systems Manager',54578,37270,3);
INSERT INTO `employees` VALUES (76196,'Mirilla','Janowski','Cost Accountant',119241,37270,3);
INSERT INTO `employees` VALUES (80529,'Lynde','Aronson','Junior Executive',77182,37270,4);
INSERT INTO `employees` VALUES (80679,'Mildrid','Sokale','Geologist II',67987,37270,4);
INSERT INTO `employees` VALUES (84791,'Hazel','Tarbert','General Manager',93760,37270,4);
INSERT INTO `employees` VALUES (95213,'Cole','Kesterton','Pharmacist',86119,37270,4);
INSERT INTO `employees` VALUES (96513,'Theresa','Binney','Food Chemist',47354,37270,5);
INSERT INTO `employees` VALUES (98374,'Estrellita','Daleman','Staff Accountant IV',70187,37270,5);
INSERT INTO `employees` VALUES (115357,'Ivy','Fearey','Structural Engineer',92710,37270,5);


DROP DATABASE IF EXISTS `sql_inventory`;
CREATE DATABASE `sql_inventory`;
USE `sql_inventory`;


CREATE TABLE `products` (
  `product_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `quantity_in_stock` int(11) NOT NULL,
  `unit_price` decimal(4,2) NOT NULL,
  PRIMARY KEY (`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `products` VALUES (1,'Foam Dinner Plate',70,1.21);
INSERT INTO `products` VALUES (2,'Pork - Bacon,back Peameal',49,4.65);
INSERT INTO `products` VALUES (3,'Lettuce - Romaine, Heart',38,3.35);
INSERT INTO `products` VALUES (4,'Brocolinni - Gaylan, Chinese',90,4.53);
INSERT INTO `products` VALUES (5,'Sauce - Ranch Dressing',94,1.63);
INSERT INTO `products` VALUES (6,'Petit Baguette',14,2.39);
INSERT INTO `products` VALUES (7,'Sweet Pea Sprouts',98,3.29);
INSERT INTO `products` VALUES (8,'Island Oasis - Raspberry',26,0.74);
INSERT INTO `products` VALUES (9,'Longan',67,2.26);
INSERT INTO `products` VALUES (10,'Broom - Push',6,1.09);

  

一、查詢

1.1查詢customers中的last_name ,first_name ,points , discount factor列為points+10

同時限制輸出結果為3行

#陳述句
use sql_store;#使用哪種資料庫
select 
    last_name, 
    first_name, 
    points, 
    points +10 as 'discount factor'
from customers
limit 3 #限制輸出內容
/**
+------------+------------+--------+-----------------+
| last_name  | first_name | points | discount factor |
+------------+------------+--------+-----------------+
| MacCaffrey | Babara     |   2323 |            2333 |
| Brushfield | Ines       |    997 |            1007 |
| Boagey     | Freddi     |   3017 |            3027 |
+------------+------------+--------+-----------------+
**/

1.2查詢order_item_notes表中的note有多少種值型別

#代碼
use sql_store;#使用哪種資料庫
select * from order_item_notes;
/**
+---------+----------+------------+-------------+
| note_id | order_Id | product_id | note        |
+---------+----------+------------+-------------+
|       1 |        1 |          2 | first note  |
|       2 |        1 |          2 | second note |
|       3 |        1 |          2 | first note  |
+---------+----------+------------+-------------+

**/
#代碼
select 
    distinct note #去除重復
from order_item_notes
/**
+-------------+
| note        |
+-------------+
| first note  |
| second note |
+-------------+
**/

1.3where子句練習

#代碼
 use sql_store;#使用哪種資料庫
 select 
     * 
 from customers 
 where points >3000#where birth_date > '1992-01-01'#where state = 'va' /**
 +-------------+------------+-----------+------------+--------------+----------------+-----------+-------+--------+
 | customer_id | first_name | last_name | birth_date | phone        | address        | city      | state | points |
 +-------------+------------+-----------+------------+--------------+----------------+-----------+-------+--------+
 |           5 | Clemmie    | Betchley  | 1973-11-07 | NULL         | 5 Spohn Circle | Arlington | TX    |   3675 |
 |           6 | Elka       | Twiddell  | 1991-09-04 | 312-480-8498 | 7 Manley Drive | Chicago   | IL    |   3073 |
 +-------------+------------+-----------+------------+--------------+----------------+-----------+-------+--------+
 **/
 #代碼 邏輯鏈接 and兩個條件同時成立,or兩個條件一個成立即可
 select * 
 from customers
 where points >= 1000 and points <= 3000
 /**
 +-------------+------------+------------+------------+--------------+----------------------+------------------+-------+--------+
 | customer_id | first_name | last_name  | birth_date | phone        | address              | city             | state | points |
 +-------------+------------+------------+------------+--------------+----------------------+------------------+-------+--------+
 |           1 | Babara     | MacCaffrey | 1986-03-28 | 781-932-9754 | 0 Sage Terrace       | Waltham          | MA    |   2273 |
 |           3 | Freddi     | Boagey     | 1985-02-07 | 719-724-7869 | 251 Springs Junction | Colorado Springs | CO    |   2967 |
 |           7 | Ilene      | Dowson     | 1964-08-30 | 615-641-4759 | 50 Lillian Crossing  | Nashville        | TN    |   1672 |
 |           9 | Romola     | Rumgay     | 1992-05-23 | 559-181-3744 | 3520 Ohio Trail      | Visalia          | CA    |   1486 |
 +-------------+------------+------------+------------+--------------+----------------------+------------------+-------+--------+
 **/
 select
     *
 from orders
 where order_date >= '2018-01-02' and status >1 or status = 2
 /**
 +----------+-------------+------------+--------+-----------------------------------------------+--------------+------------+
 | order_id | customer_id | order_date | status | comments                                      | shipped_date | shipper_id |
 +----------+-------------+------------+--------+-----------------------------------------------+--------------+------------+
 |        2 |           7 | 2018-08-02 |      2 | NULL                                          | 2018-08-03   |          4 |
 |        5 |           5 | 2017-08-25 |      2 |                                               | 2017-08-26   |          3 |
 |        7 |           2 | 2018-09-22 |      2 | NULL                                          | 2018-09-23   |          4 |
 |        9 |          10 | 2017-07-05 |      2 | Nulla mollis molestie lorem. Quisque ut erat. | 2017-07-06   |          1 |
 |       10 |           6 | 2018-04-22 |      2 | NULL                                          | 2018-04-23   |          2 |
 +----------+-------------+------------+--------+-----------------------------------------------+--------------+------------+
 **/
 #代碼 in where state in ('va', 'GA', 'FL')== where state = 'VA' or state = 'GA' or state = 'FL'
 select * 
 from customers
 #where state = 'VA' or state = 'GA' or state = 'FL'
 where state in ('va', 'GA', 'FL') /**
 +-------------+------------+------------+------------+--------------+------------------------+----------+-------+--------+
 | customer_id | first_name | last_name  | birth_date | phone        | address                | city     | state | points |
 +-------------+------------+------------+------------+--------------+------------------------+----------+-------+--------+
 |           2 | Ines       | Brushfield | 1986-04-13 | 804-427-9456 | 14187 Commercial Trail | Hampton  | VA    |    947 |
 |           4 | Ambur      | Roseburgh  | 1974-04-14 | 407-231-8017 | 30 Arapahoe Terrace    | Orlando  | FL    |    457 |
 |           8 | Thacher    | Naseby     | 1993-07-17 | 941-527-3977 | 538 Mosinee Center     | Sarasota | FL    |    205 |
 |          10 | Levy       | Mynett     | 1969-10-13 | 404-246-3370 | 68 Lawn Avenue         | Atlanta  | GA    |    796 |
 +-------------+------------+------------+------------+--------------+------------------------+----------+-------+--------+
 **/

1.4匹配

use sql_store;#使用哪種資料庫
#查詢customers中last_name的第二個字母為y的所有資訊
select * 
from customers
where last_name like '_y%'
/**
+-------------+------------+-----------+------------+--------------+----------------+---------+-------+--------+
| customer_id | first_name | last_name | birth_date | phone        | address        | city    | state | points |
+-------------+------------+-----------+------------+--------------+----------------+---------+-------+--------+
|          10 | Levy       | Mynett    | 1969-10-13 | 404-246-3370 | 68 Lawn Avenue | Atlanta | GA    |    796 |
+-------------+------------+-----------+------------+--------------+----------------+---------+-------+--------+
**/
#查詢customers中phone 帶有9的所有資訊,并限制輸出3行資訊
select *
from customers
#where address like '%trail%' or
    #address like '%avenue%'
where phone like '%9%'
limit 3
/**
+-------------+------------+------------+------------+--------------+------------------------+------------------+-------+--------+
| customer_id | first_name | last_name  | birth_date | phone        | address                | city             | state | points |
+-------------+------------+------------+------------+--------------+------------------------+------------------+-------+--------+
|           1 | Babara     | MacCaffrey | 1986-03-28 | 781-932-9754 | 0 Sage Terrace         | Waltham          | MA    |   2273 |
|           2 | Ines       | Brushfield | 1986-04-13 | 804-427-9456 | 14187 Commercial Trail | Hampton          | VA    |    947 |
|           3 | Freddi     | Boagey     | 1985-02-07 | 719-724-7869 | 251 Springs Junction   | Colorado Springs | CO    |   2967 |
+-------------+------------+------------+------------+--------------+------------------------+------------------+-------+--------+
**/
#regexp用法
select *
from customers
#where last_name like '%field%'
#where last_name regexp 'field'#含有
#where last_name regexp '^field'#開頭
#where last_name regexp 'field$' #結尾
#where last_name regexp 'field|mac|rose'#或者
#where last_name regexp '[gim]e'#ge/ie/me 取一個元素
#where last_name regexp '[a-h]e'#ae/……/he 范圍

#order by 分組 資料顯示限制為3條
select *
from customers
#order by first_name desc#按照first_name分組并倒敘
order by first_name #按照first_name分組
limit 3
/**
+-------------+------------+------------+------------+--------------+---------------------+-----------+-------+--------+
| customer_id | first_name | last_name  | birth_date | phone        | address             | city      | state | points |
+-------------+------------+------------+------------+--------------+---------------------+-----------+-------+--------+
|           4 | Ambur      | Roseburgh  | 1974-04-14 | 407-231-8017 | 30 Arapahoe Terrace | Orlando   | FL    |    457 |
|           1 | Babara     | MacCaffrey | 1986-03-28 | 781-932-9754 | 0 Sage Terrace      | Waltham   | MA    |   2273 |
|           5 | Clemmie    | Betchley   | 1973-11-07 | NULL         | 5 Spohn Circle      | Arlington | TX    |   3675 |
+-------------+------------+------------+------------+--------------+---------------------+-----------+-------+--------+
**/
select *, quantity * unit_price as total_price
from order_items
where order_id = 2
order by quantity * unit_price desc
limit 3
/**
+----------+------------+----------+------------+-------------+
| order_id | product_id | quantity | unit_price | total_price |
+----------+------------+----------+------------+-------------+
|        2 |          1 |        2 |       9.10 |       18.20 |
|        2 |          4 |        4 |       1.66 |        6.64 |
|        2 |          6 |        2 |       2.94 |        5.88 |
+----------+------------+----------+------------+-------------+
**/

1.5連接

#代碼 聯合orders 和customers 查詢order_id, o.customer_id, last_name, first_name
select order_id, o.customer_id, last_name, first_name
from orders o
join customers 
    on o.customer_id = customers.customer_id
/**
+----------+-------------+------------+------------+
| order_id | customer_id | last_name  | first_name |
+----------+-------------+------------+------------+
|        4 |           2 | Brushfield | Ines       |
|        7 |           2 | Brushfield | Ines       |
|        5 |           5 | Betchley   | Clemmie    |
|        8 |           5 | Betchley   | Clemmie    |
|        1 |           6 | Twiddell   | Elka       |
|       10 |           6 | Twiddell   | Elka       |
|        2 |           7 | Dowson     | Ilene      |
|        3 |           8 | Naseby     | Thacher    |
|        6 |          10 | Mynett     | Levy       |
|        9 |          10 | Mynett     | Levy       |
+----------+-------------+------------+------------+
**/

#聯合orders /customers  和order_statuses 查詢
use sql_store;
select o.order_id, o.order_date, c.first_name, c.last_name, os.name as status
from orders o
join customers c
    on o.customer_id = c.customer_id
join order_statuses os 
    on os.order_status_id = o.status
/**
+----------+------------+------------+------------+-----------+
| order_id | order_date | first_name | last_name  | status    |
+----------+------------+------------+------------+-----------+
|        1 | 2019-01-30 | Elka       | Twiddell   | Processed |
|        3 | 2017-12-01 | Thacher    | Naseby     | Processed |
|        4 | 2017-01-22 | Ines       | Brushfield | Processed |
|        6 | 2018-11-18 | Levy       | Mynett     | Processed |
|        8 | 2018-06-08 | Clemmie    | Betchley   | Processed |
|        2 | 2018-08-02 | Ilene      | Dowson     | Shipped   |
|        5 | 2017-08-25 | Clemmie    | Betchley   | Shipped   |
|        7 | 2018-09-22 | Ines       | Brushfield | Shipped   |
|        9 | 2017-07-05 | Levy       | Mynett     | Shipped   |
|       10 | 2018-04-22 | Elka       | Twiddell   | Shipped   |
+----------+------------+------------+------------+-----------+
**/
#聯合payments /clients 和payment_methods 查詢p.date, p.invoice_id, #p.amount, c.name, pm.name
use sql_invoicing;
select p.date, p.invoice_id, p.amount, c.name, pm.name
from payments p
join clients c
    on p.client_id = c.client_id
join payment_methods pm
    on p.payment_method = pm.payment_method_id
/**
+------------+------------+--------+-------------+-------------+
| date       | invoice_id | amount | name        | name        |
+------------+------------+--------+-------------+-------------+
| 2019-02-12 |          2 |   8.18 | Topiclounge | Credit Card |
| 2019-01-03 |          6 |  74.55 | Vinte       | Credit Card |
| 2019-01-11 |         11 |   0.03 | Yadel       | Credit Card |
| 2019-01-26 |         13 |  87.44 | Topiclounge | Credit Card |
| 2019-01-15 |         15 |  80.31 | Yadel       | Credit Card |
| 2019-01-15 |         17 |  68.10 | Yadel       | Credit Card |
| 2019-01-08 |         18 |  32.77 | Topiclounge | Credit Card |
| 2019-01-08 |         18 |  10.00 | Topiclounge | Cash        |
+------------+------------+--------+-------------+-------------+
**/
#右連接customers 和orders 查詢customer_id,first_name,order_id
use sql_store;
select c.customer_id, c.first_name, o.order_id
from customers c
right join orders o#left join orders o
    on c.customer_id = o.customer_id
order by c.customer_id
/**
+-------------+------------+----------+
| customer_id | first_name | order_id |
+-------------+------------+----------+
|           2 | Ines       |        4 |
|           2 | Ines       |        7 |
|           5 | Clemmie    |        5 |
|           5 | Clemmie    |        8 |
|           6 | Elka       |        1 |
|           6 | Elka       |       10 |
|           7 | Ilene      |        2 |
|           8 | Thacher    |        3 |
|          10 | Levy       |        6 |
|          10 | Levy       |        9 |
+-------------+------------+----------+
**/
#左連接orders ,shippers ,customers ,order_statuses
use sql_store;
select o.order_date, o.order_id,c.first_name as customer, s.name, os.name as status
from orders o
left join shippers s
    on o.shipper_id = s.shipper_id
left join customers c
    on c.customer_id = o.customer_id
join order_statuses os
    on o.status = os.order_status_id
/**
+------------+----------+----------+------------------------+-----------+
| order_date | order_id | customer | name                   | status    |
+------------+----------+----------+------------------------+-----------+
| 2019-01-30 |        1 | Elka     | NULL                   | Processed |
| 2017-12-01 |        3 | Thacher  | NULL                   | Processed |
| 2017-01-22 |        4 | Ines     | NULL                   | Processed |
| 2018-11-18 |        6 | Levy     | NULL                   | Processed |
| 2018-06-08 |        8 | Clemmie  | NULL                   | Processed |
| 2018-08-02 |        2 | Ilene    | Mraz, Renner and Nolan | Shipped   |
| 2017-08-25 |        5 | Clemmie  | Satterfield LLC        | Shipped   |
| 2018-09-22 |        7 | Ines     | Mraz, Renner and Nolan | Shipped   |
| 2017-07-05 |        9 | Levy     | Hettinger LLC          | Shipped   |
| 2018-04-22 |       10 | Elka     | Schinner-Predovic      | Shipped   |
+------------+----------+----------+------------------------+-----------+
**/
#using連接orders ,customers ,shippers 查詢order_id, first_name, shipper
#注意連接的兩張表必須有相同的欄位
use sql_store;
select o.order_id, c.first_name, sh.name as shipper
from orders o
join customers c
    using (customer_id)
left join shippers sh
    using (shipper_id)
/**
+----------+------------+------------------------+
| order_id | first_name | shipper                |
+----------+------------+------------------------+
|        1 | Elka       | NULL                   |
|        2 | Ilene      | Mraz, Renner and Nolan |
|        3 | Thacher    | NULL                   |
|        4 | Ines       | NULL                   |
|        5 | Clemmie    | Satterfield LLC        |
|        6 | Levy       | NULL                   |
|        7 | Ines       | Mraz, Renner and Nolan |
|        8 | Clemmie    | NULL                   |
|        9 | Levy       | Hettinger LLC          |
|       10 | Elka       | Schinner-Predovic      |
+----------+------------+------------------------+
**/
#from shippers sh cross join products p == from shippers sh, products p
use sql_store;
select sh.name as shipper, p.name as product    
from shippers sh 
cross join products p #from shippers sh, products p
order by sh.name desc
limit 3
/**
+-----------------------------+---------------------------+
| shipper                     | product                   |
+-----------------------------+---------------------------+
| Waters, Mayert and Prohaska | Foam Dinner Plate         |
| Waters, Mayert and Prohaska | Lettuce - Romaine, Heart  |
| Waters, Mayert and Prohaska | Pork - Bacon,back Peameal |
+-----------------------------+---------------------------+
**/
#union連接兩個查詢
use sql_store;
select order_id, order_date, 'Axtive' as status
    from orders 
    where order_date >= '2019-01-01'
union
select order_id, order_date, 'Archived' as status
    from orders 
    where order_date < '2019-01-01'
limit 5
/**
+----------+------------+----------+
| order_id | order_date | status   |
+----------+------------+----------+
|        1 | 2019-01-30 | Axtive   |
|        2 | 2018-08-02 | Archived |
|        3 | 2017-12-01 | Archived |
|        4 | 2017-01-22 | Archived |
|        5 | 2017-08-25 | Archived |
+----------+------------+----------+
**/

二、插入

#customers 中插入一行資料
use sql_store;
insert into customers (customer_id, first_name,last_name,birth_date,phone,address,city,state,points)
values (default, 'mark', 'reaper', '1991-01-01', '15690679736', 'address', 'city', 'CA', 200)

#shippers 中插入兩行資料
use sql_store;
insert into shippers (name)
values ('Shippers1'), ('Shippers2')

#products 中插入兩行資料
use sql_store;
insert into products (name,quantity_in_stock, unit_price)
values ('Product1', 10, 1.95), ('Product2', 1, 8.95)

#orders 中插入一行資料
use sql_store;
insert into orders (customer_id, order_date, status)
values (1, '2019-01-02', 1)

#order_items中插入一行資料
insert into order_items
values (LAST_INSERT_ID(),11,1,2.98),(LAST_INSERT_ID(),2,1,2.88)
    
#將orders中order_date <'2019-01-01'的資料插入到orders_archived 中
insert into orders_archived 
select * from orders
where order_date <'2019-01-01'

三、修改

#invoices中invoice_id 為 1的payment_total改為100,payment_date 改為2019-03-02
use sql_invoicing;
update invoices
set payment_total = 100, payment_date = '2019-03-02'
where invoice_id = 1

四、洗掉

#洗掉orders_archived中customer_id 為 7的資料
use sql_store;
delete from orders_archived
where customer_id = 7

檔案來源參考https://www.bilibili.com/video/av75855831?from=search&seid=175084983081237169

本文章僅可用于學習交流,如果用于其他用途責任自行承擔

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/80313.html

標籤:MySQL

上一篇:mysql資料庫批量執行sql檔案對資料庫進行操作【windows版本】

下一篇:MySQL面試筆試題集-BAT

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • GPU虛擬機創建時間深度優化

    **?桔妹導讀:**GPU虛擬機實體創建速度慢是公有云面臨的普遍問題,由于通常情況下創建虛擬機屬于低頻操作而未引起業界的重視,實際生產中還是存在對GPU實體創建時間有苛刻要求的業務場景。本文將介紹滴滴云在解決該問題時的思路、方法、并展示最終的優化成果。 從公有云服務商那里購買過虛擬主機的資深用戶,一 ......

    uj5u.com 2020-09-10 06:09:13 more
  • 可編程網卡芯片在滴滴云網路的應用實踐

    **?桔妹導讀:**隨著云規模不斷擴大以及業務層面對延遲、帶寬的要求越來越高,采用DPDK 加速網路報文處理的方式在橫向縱向擴展都出現了局限性。可編程芯片成為業界熱點。本文主要講述了可編程網卡芯片在滴滴云網路中的應用實踐,遇到的問題、帶來的收益以及開源社區貢獻。 #1. 資料中心面臨的問題 隨著滴滴 ......

    uj5u.com 2020-09-10 06:10:21 more
  • 滴滴資料通道服務演進之路

    **?桔妹導讀:**滴滴資料通道引擎承載著全公司的資料同步,為下游實時和離線場景提供了必不可少的源資料。隨著任務量的不斷增加,資料通道的整體架構也隨之發生改變。本文介紹了滴滴資料通道的發展歷程,遇到的問題以及今后的規劃。 #1. 背景 資料,對于任何一家互聯網公司來說都是非常重要的資產,公司的大資料 ......

    uj5u.com 2020-09-10 06:11:05 more
  • 滴滴AI Labs斬獲國際機器翻譯大賽中譯英方向世界第三

    **桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......

    uj5u.com 2020-09-10 06:11:29 more
  • MPP (Massively Parallel Processing)大規模并行處理

    1、什么是mpp? MPP (Massively Parallel Processing),即大規模并行處理,在資料庫非共享集群中,每個節點都有獨立的磁盤存盤系統和記憶體系統,業務資料根據資料庫模型和應用特點劃分到各個節點上,每臺資料節點通過專用網路或者商業通用網路互相連接,彼此協同計算,作為整體提供 ......

    uj5u.com 2020-09-10 06:11:41 more
  • 滴滴資料倉庫指標體系建設實踐

    **桔妹導讀:**指標體系是什么?如何使用OSM模型和AARRR模型搭建指標體系?如何統一流程、規范化、工具化管理指標體系?本文會對建設的方法論結合滴滴資料指標體系建設實踐進行解答分析。 #1. 什么是指標體系 ##1.1 指標體系定義 指標體系是將零散單點的具有相互聯系的指標,系統化的組織起來,通 ......

    uj5u.com 2020-09-10 06:12:52 more
  • 單表千萬行資料庫 LIKE 搜索優化手記

    我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......

    uj5u.com 2020-09-10 06:13:25 more
  • 滴滴Ceph分布式存盤系統優化之鎖優化

    **桔妹導讀:**Ceph是國際知名的開源分布式存盤系統,在工業界和學術界都有著重要的影響。Ceph的架構和演算法設計發表在國際系統領域頂級會議OSDI、SOSP、SC等上。Ceph社區得到Red Hat、SUSE、Intel等大公司的大力支持。Ceph是國際云計算領域應用最廣泛的開源分布式存盤系統, ......

    uj5u.com 2020-09-10 06:14:51 more
  • es~通過ElasticsearchTemplate進行聚合~嵌套聚合

    之前寫過《es~通過ElasticsearchTemplate進行聚合操作》的文章,這一次主要寫一個嵌套的聚合,例如先對sex集合,再對desc聚合,最后再對age求和,共三層嵌套。 Aggregations的部分特性類似于SQL語言中的group by,avg,sum等函式,Aggregation ......

    uj5u.com 2020-09-10 06:14:59 more
  • 爬蟲日志監控 -- Elastc Stack(ELK)部署

    傻瓜式部署,只需替換IP與用戶 導讀: 現ELK四大組件分別為:Elasticsearch(核心)、logstash(處理)、filebeat(采集)、kibana(可視化) 下載均在https://www.elastic.co/cn/downloads/下tar包,各組件版本最好一致,配合fdm會 ......

    uj5u.com 2020-09-10 06:15:05 more
最新发布
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:33:24 more
  • MySQL中binlog備份腳本分享

    關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......

    uj5u.com 2023-04-20 08:28:06 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:27:27 more
  • 快取與資料庫雙寫一致性幾種策略分析

    本文將對幾種快取與資料庫保證資料一致性的使用方式進行分析。為保證高并發性能,以下分析場景不考慮執行的原子性及加鎖等強一致性要求的場景,僅追求最終一致性。 ......

    uj5u.com 2023-04-20 08:26:48 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:26:35 more
  • 云時代,MySQL到ClickHouse資料同步產品對比推薦

    ClickHouse 在執行分析查詢時的速度優勢很好的彌補了MySQL的不足,但是對于很多開發者和DBA來說,如何將MySQL穩定、高效、簡單的同步到 ClickHouse 卻很困難。本文對比了 NineData、MaterializeMySQL(ClickHouse自帶)、Bifrost 三款產品... ......

    uj5u.com 2023-04-20 08:26:29 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:25:13 more
  • Redis 報”OutOfDirectMemoryError“(堆外記憶體溢位)

    Redis 報錯“OutOfDirectMemoryError(堆外記憶體溢位) ”問題如下: 一、報錯資訊: 使用 Redis 的業務介面 ,產生 OutOfDirectMemoryError(堆外記憶體溢位),如圖: 格式化后的報錯資訊: { "timestamp": "2023-04-17 22: ......

    uj5u.com 2023-04-20 08:24:54 more
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:24:03 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:23:11 more