当前位置:网站首页>Database Experiment 3 data update experiment
Database Experiment 3 data update experiment
2022-04-23 21:45:00 【Hebuter-Rui】
1. The experiment purpose
Familiar with database data update operation , Able to use SQL Statement to add data to the database 、 Delete 、 Modify the operating .
2. The contents and requirements of the experiment
in the light of tpch Database or self built database test Design single line insert 、 Batch insert 、 Modify and delete data , Understand and master insert、delete and update The various components of the grammatical structure , Combined nesting SQL Subquery , Design several different forms of statements , And debugging passed .
3. The experimental steps
(1) Insert a record into the supplier table , The value of each column should be given reasonably .
Source code :
INSERT INTO supplier (
suppkey,
name,
address,
nationkey,
phone,
acctbal,
comment
)
VALUES(
131209,
' Tencent holdings ',
' Shenzhen, Guangdong Province ',
227,
'020-2456741',
1300098203.20,
' nothing '
);
Results screenshots :( The following figure shows the results filtered using visualization , You can also use SELECT Statement to find the result )
(2) Insert all the information of all Chinese customers into a new customer table (customernew) in .
Source code :
CREATE TABLE customernew AS SELECT
*
FROM
customer
WHERE
1 = 0;
INSERT INTO customernew SELECT
customer.*
FROM
customer,
nation
WHERE
customer.nationkey = nation.nationkey
AND nation. NAME = ' China ';
Results screenshots :
(3) Insert the information of each customer and its total shopping quantity and total shopping price into the customer statistics table (cusshopping)
Source code :
CREATE TABLE cusshopping AS SELECT
customer.custkey,
customer. NAME,
COUNT(*) AS shopping_num,
SUM(totalprice) AS price_sum
FROM
customer,
orders
WHERE
customer.custkey = orders.custkey
GROUP BY
orders.custkey
ORDER BY
orders.custkey;
Results screenshots :
(4) hold “ Shenzhen Hongyun Trading Co., Ltd ” The supply price of all parts supplied is reduced 20%.
Source code :
UPDATE partsupp
SET supplycost = supplycost * 0.8
WHERE
suppkey IN (
SELECT
suppkey
FROM
supplier
WHERE
NAME = ' Shenzhen Hongyun Trading Co., Ltd '
);
Results screenshots :( The following figure shows the results filtered using visualization , You can also use SELECT Statement to find the result )
Before updating
After the update
(5) Update the order price in the order details table , Order details price (extendedprice)= wholesale price (part.retailprice)* Number of parts (quantity).
Source code :
UPDATE lineitem,
part
SET lineitem.extendedprice = lineitem.quantity * part.retailprice
WHERE
lineitem.partkey = part.partkey;
Results screenshots :
Before updating
After the update
(6) Delete customer “ Tong Shuai ” All order detail records and order records .
Source code :
DELETE
FROM
lineitem
WHERE
orderkey IN (
SELECT
orderkey
FROM
orders,
customer
WHERE
customer. NAME = ' Tong Shuai '
AND orders.custkey = customer.custkey
);
DELETE
FROM
orders
WHERE
custkey IN (
SELECT
custkey
FROM
customer
WHERE
NAME = ' Tong Shuai '
);
Results screenshots :( The following figure shows the results filtered using visualization , You can also use SELECT Statement to find the result )
Before deleting
After deleting
(7) Delete “ Australia ” All supplier information for .
Source code :
DELETE
FROM
lineitem
WHERE
suppkey IN (
SELECT
suppkey
FROM
supplier
WHERE
nationkey IN
(SELECT nationkey
FROM nation
WHERE NAME = ' Australia ')
);
DELETE
FROM
partsupp
WHERE
suppkey IN (
SELECT
suppkey
FROM
supplier
WHERE
nationkey IN
(SELECT nationkey
FROM nation
WHERE NAME = ' Australia ')
);
DELETE
FROM
supplier
WHERE
nationkey IN (
SELECT
nationkey
FROM
nation
WHERE
NAME = ' Australia '
);
Results screenshots :( The following figure shows the results filtered using visualization , You can also use SELECT Statement to find the result )
Before deleting
After deleting
版权声明
本文为[Hebuter-Rui]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204200618536956.html
边栏推荐
- 2.整理华子面经--2
- [leetcode refers to offer 25. Merge two sorted linked lists (simple)]
- Rust更适合经验较少的程序员?
- Chrome 94 引入具有争议的 Idle Detection API,苹果和Mozilla反对
- C, print the source program of beautiful bell triangle
- Plato Farm元宇宙IEO上线四大,链上交易颇高
- 1. Finishing huazi Mianjing -- 1
- ERP function_ Financial management_ The difference between red and blue words in invoices
- IOT design and development
- [leetcode refers to the substructure of offer 26. Tree (medium)]
猜你喜欢
ROS learning notes - tutorial on the use of ROS
Problem brushing plan -- dynamic programming (III)
How to make Jenkins job run automatically after startup
Express③(使用Express编写接口、跨域有关问题)
JS prototype and prototype chain
Is rust more suitable for less experienced programmers?
Arm architecture assembly instructions, registers and some problems
2. Finishing huazi Mianjing -- 2
Deno 1.13.2 发布
[leetcode refers to the two numbers of offer 57. And S (simple)]
随机推荐
[leetcode refers to offer 32 - III. print binary tree III from top to bottom (medium)]
Solve importerror: cannot import name 'imread' from 'SciPy misc‘
Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
【SDU Chart Team - Core】SVG属性类设计之枚举
2.整理华子面经--2
危机即机遇,远程办公效率为何会提升?
C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
Flomo software recommendation
How to use the project that created SVN for the first time
Question brushing plan - depth first search (II)
Two Stage Detection
[※ leetcode refers to offer 48. The longest substring without repeated characters (medium)]
Norm normalization in tensorflow and pytorch of records
2. Finishing huazi Mianjing -- 2
A solution of C batch query
[leetcode sword finger offer 28. Symmetric binary tree (simple)]
How Axure installs a catalog
Oracle intercepts special characters
Xiaomi mobile phone has abandoned the "Mi" brand all over the world and switched to the full name brand of "Xiaomi"
Introduction to tensorrt