当前位置:网站首页>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
边栏推荐
- ros功能包内自定义消息引用失败
- Subcontracting of wechat applet based on uni app
- What if Jenkins forgot his password
- [leetcode refers to the maximum profit of offer 63. Stock (medium)]
- Daily operation and maintenance knowledge -- 1
- Thread safe sigleton (singleton mode)
- Minecraft 1.12.2模组开发(四十三) 自定义盾牌(Shield)
- Detailed explanation of basic assembly instructions of x86 architecture
- Thinkphp5 + data large screen display effect
- Online Excel to CSV tool
猜你喜欢

Based on jsplumb JS to achieve multi list one to many connection effect

Display, move, rotate

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:app:stripDe
![[leetcode refers to the two numbers of offer 57. And S (simple)]](/img/c2/7c1434e3c0bbcc6d6364361c3a3ab4.png)
[leetcode refers to the two numbers of offer 57. And S (simple)]
![[leetcode refers to offer 47. Maximum value of gift (medium)]](/img/b4/34b3c74516e3b1ba93b7d84916dadc.png)
[leetcode refers to offer 47. Maximum value of gift (medium)]

Pipes and xargs

Deno 1.13.2 发布

JS prototype and prototype chain

C, print the source program of beautiful bell triangle

C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
随机推荐
Google tries to use rust in Chrome
C# ftpHelper
airbase 初步分析
YOLOv5 Unable to find a valid cuDNN algorithm to run convolution
[leetcode refers to the maximum profit of offer 63. Stock (medium)]
Express ③ (use express to write interface and cross domain related issues)
[leetcode refers to offer 22. The penultimate node in the linked list (simple)]
Ubutnu20 installer centernet
Prim、Kruskal
ROS learning notes - tutorial on the use of ROS
Crisis is opportunity. Why will the efficiency of telecommuting improve?
Realrange, reduce, repeat and einops in einops package layers. Rearrange and reduce in torch. Processing methods of high-dimensional data
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:app:stripDe
South Korea may ban apple and Google from offering commission to developers, the first in the world
Oracle intercepts special characters
Pycharm Chinese plug-in
[leetcode refers to offer 27. Image of binary tree (simple)]
ros功能包内自定义消息引用失败
IOT design and development
Opencv application -- jigsaw puzzle