PTA - 数据库合集54

本文介绍了三个数据库操作示例,包括:1)整体增加订单运费50%;2)针对员工编号为3和4的订单降低运费5%;3)对运费超过30.00的订单提高相关产品单价15%。这些操作通过UPDATE SQL语句实现,涉及订单表orders和订单详情表orderdetails。
摘要由CSDN通过智能技术生成

 目录

10-199 C2-1修改订单运费

10-200 C2-2修改特定职工的订单运费

10-201 C2-3根据运费调整订单单价


10-199 C2-1修改订单运费

分数 20

全屏浏览题目

切换布局

作者 柯海丰

单位 浙大城市学院

修改订单表(orders)中的运费,将每单运费(Freight)增加50%
提示:请使用UPDATE语句作答。

表结构:

orders表:

列名数据类型长度主码说明
OrderIDint11订单编号
CustomerIDvarchar5顾客编号
EmployeeIDint11员工编号
OrderDatedatetime,订购日期
RequiredDatedatetime,预计到达日期
ShippedDatedatetime,发货日期
ShipViaint11运货商
Freightdecimal10,4运费
ShipNamevarchar40货主姓名
ShipAddressvarchar60货主地址
ShipCityvarchar15所在城市
ShipRegionvarchar15区域
ShipPostalCodevarchar10邮政编码
ShipCountryvarchar15所在国家

表样例

orders表:

OrderIDCustomerIDEmployeeIDOrderDateRequiredDateShippedDateShipViaFreightShipNameShipAddressShipCityShipRegionShipPostalCodeShipCountry
10248VINET51996/7/4 00:00:001996/8/1 00:00:001996/7/16 00:00:00332.3800Vins et alcools Chevalier59 rue de l-AbbayeReims51100France
10249TOMSP61996/7/5 00:00:001996/8/16 00:00:001996/7/10 00:00:00111.6100Toms SpezialittenLuisenstr. 48Mnster44087Germany
10250HANAR41996/7/8 00:00:001996/8/5 00:00:001996/7/12 00:00:00265.8300Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10251VICTE31996/7/8 00:00:001996/8/5 00:00:001996/7/15 00:00:00141.3400Victuailles en stock2, rue du CommerceLyon69004France
10252SUPRD41996/7/9 00:00:001996/8/6 00:00:001996/7/11 00:00:00251.3000Suprmes dlicesBoulevard Tirou, 255CharleroiB-6000Belgium
10253HANAR31996/7/10 00:00:001996/7/24 00:00:001996/7/16 00:00:00258.1700Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10254CHOPS51996/7/11 00:00:001996/8/8 00:00:001996/7/23 00:00:00222.9800Chop-suey ChineseHauptstr. 31Bern3012Switzerland
10255RICSU91996/7/12 00:00:001996/8/9 00:00:001996/7/15 00:00:003148.3300Richter SupermarktStarenweg 5Genve1204Switzerland
10256WELLI31996/7/15 00:00:001996/8/12 00:00:001996/7/17 00:00:00213.9700Wellington ImportadoraRua do Mercado, 12ResendeSP08737-363Brazil
10257HILAA41996/7/16 00:00:001996/8/13 00:00:001996/7/22 00:00:00381.9100HILARION-AbastosCarrera 22 con Ave. Carlos Soublette #8-35San CristbalTchira5022Venezuela

输出样例:

OrderIDCustomerIDEmployeeIDOrderDateRequiredDateShippedDateShipViaFreightShipNameShipAddressShipCityShipRegionShipPostalCodeShipCountry
10248VINET51996-07-04 00:00:001996-08-01 00:00:001996-07-16 00:00:00348.57Vins et alcools Chevalier59 rue de l-AbbayeReims51100France
10249TOMSP61996-07-05 00:00:001996-08-16 00:00:001996-07-10 00:00:00117.415Toms SpezialittenLuisenstr. 48Mnster44087Germany
10250HANAR41996-07-08 00:00:001996-08-05 00:00:001996-07-12 00:00:00298.745Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10251VICTE31996-07-08 00:00:001996-08-05 00:00:001996-07-15 00:00:00162.01Victuailles en stock2, rue du CommerceLyon69004France
10252SUPRD41996-07-09 00:00:001996-08-06 00:00:001996-07-11 00:00:00276.95Suprmes dlicesBoulevard Tirou, 255CharleroiB-6000Belgium
10253HANAR31996-07-10 00:00:001996-07-24 00:00:001996-07-16 00:00:00287.255Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10254CHOPS51996-07-11 00:00:001996-08-08 00:00:001996-07-23 00:00:00234.47Chop-suey ChineseHauptstr. 31Bern3012Switzerland
10255RICSU91996-07-12 00:00:001996-08-09 00:00:001996-07-15 00:00:003222.495Richter SupermarktStarenweg 5Genve1204Switzerland
10256WELLI31996-07-15 00:00:001996-08-12 00:00:001996-07-17 00:00:00220.955Wellington ImportadoraRua do Mercado, 12ResendeSP08737-363Brazil
10257HILAA41996-07-16 00:00:001996-08-13 00:00:001996-07-22 00:00:003122.865HILARION-AbastosCarrera 22 con Ave. Carlos Soublette #8-35San CristbalTchira5022Venezuela
UPDATE
    orders
SET
    Freight = Freight * 1.5;

    

10-200 C2-2修改特定职工的订单运费

分数 20

全屏浏览题目

切换布局

作者 柯海丰

单位 浙大城市学院

修改订单表(orders)员工编号(EmployeeID)34的员工的订单,将每单运费(Freight)减少5%

提示:请使用UPDATE语句作答。

表结构:

orders表:

列名数据类型长度主码说明
OrderIDint11订单编号
CustomerIDvarchar5顾客编号
EmployeeIDint11员工编号
OrderDatedatetime,订购日期
RequiredDatedatetime,预计到达日期
ShippedDatedatetime,发货日期
ShipViaint11运货商
Freightdecimal10,4运费
ShipNamevarchar40货主姓名
ShipAddressvarchar60货主地址
ShipCityvarchar15所在城市
ShipRegionvarchar15区域
ShipPostalCodevarchar10邮政编码
ShipCountryvarchar15所在国家

表样例

orders表:

OrderIDCustomerIDEmployeeIDOrderDateRequiredDateShippedDateShipViaFreightShipNameShipAddressShipCityShipRegionShipPostalCodeShipCountry
10248VINET51996/7/4 00:00:001996/8/1 00:00:001996/7/16 00:00:00332.3800Vins et alcools Chevalier59 rue de l-AbbayeReims51100France
10249TOMSP61996/7/5 00:00:001996/8/16 00:00:001996/7/10 00:00:00111.6100Toms SpezialittenLuisenstr. 48Mnster44087Germany
10250HANAR41996/7/8 00:00:001996/8/5 00:00:001996/7/12 00:00:00265.8300Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10251VICTE31996/7/8 00:00:001996/8/5 00:00:001996/7/15 00:00:00141.3400Victuailles en stock2, rue du CommerceLyon69004France
10252SUPRD41996/7/9 00:00:001996/8/6 00:00:001996/7/11 00:00:00251.3000Suprmes dlicesBoulevard Tirou, 255CharleroiB-6000Belgium
10253HANAR31996/7/10 00:00:001996/7/24 00:00:001996/7/16 00:00:00258.1700Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10254CHOPS51996/7/11 00:00:001996/8/8 00:00:001996/7/23 00:00:00222.9800Chop-suey ChineseHauptstr. 31Bern3012Switzerland
10255RICSU91996/7/12 00:00:001996/8/9 00:00:001996/7/15 00:00:003148.3300Richter SupermarktStarenweg 5Genve1204Switzerland
10256WELLI31996/7/15 00:00:001996/8/12 00:00:001996/7/17 00:00:00213.9700Wellington ImportadoraRua do Mercado, 12ResendeSP08737-363Brazil
10257HILAA41996/7/16 00:00:001996/8/13 00:00:001996/7/22 00:00:00381.9100HILARION-AbastosCarrera 22 con Ave. Carlos Soublette #8-35San CristbalTchira5022Venezuela

输出样例:

OrderIDCustomerIDEmployeeIDOrderDateRequiredDateShippedDateShipViaFreightShipNameShipAddressShipCityShipRegionShipPostalCodeShipCountry
10248VINET51996/7/4 00:00:001996/8/1 00:00:001996/7/16 00:00:00332.3800Vins et alcools Chevalier59 rue de l-AbbayeReims51100France
10249TOMSP61996/7/5 00:00:001996/8/16 00:00:001996/7/10 00:00:00111.6100Toms SpezialittenLuisenstr. 48Mnster44087Germany
10250HANAR41996-07-08 00:00:001996-08-05 00:00:001996-07-12 00:00:00262.5385Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10251VICTE31996-07-08 00:00:001996-08-05 00:00:001996-07-15 00:00:00139.273Victuailles en stock2, rue du CommerceLyon69004France
10252SUPRD41996-07-09 00:00:001996-08-06 00:00:001996-07-11 00:00:00248.735Suprmes dlicesBoulevard Tirou, 255CharleroiB-6000Belgium
10253HANAR31996-07-10 00:00:001996-07-24 00:00:001996-07-16 00:00:00255.2615Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10254CHOPS51996/7/11 00:00:001996/8/8 00:00:001996/7/23 00:00:00222.9800Chop-suey ChineseHauptstr. 31Bern3012Switzerland
10255RICSU91996/7/12 00:00:001996/8/9 00:00:001996/7/15 00:00:003148.3300Richter SupermarktStarenweg 5Genve1204Switzerland
10256WELLI31996-07-15 00:00:001996-08-12 00:00:001996-07-17 00:00:00213.2715Wellington ImportadoraRua do Mercado, 12ResendeSP08737-363Brazil
10257HILAA41996-07-16 00:00:001996-08-13 00:00:001996-07-22 00:00:00377.8145HILARION-AbastosCarrera 22 con Ave. Carlos Soublette #8-35San CristbalTchira5022Venezuela
UPDATE
    orders
SET
    Freight = Freight * 0.95
WHERE
    EmployeeID = 3 OR EmployeeID = 4;
    

10-201 C2-3根据运费调整订单单价

分数 20

全屏浏览题目

切换布局

作者 柯海丰

单位 浙大城市学院

对于运费(Freight)超过30.00的订单,将其相关的订单详情表(orderdetails)中产品的单价(UnitPrice)提高15%

提示:请使用UPDATE语句作答。

表结构:

orderdetails表:

列名数据类型长度主码说明
OrderIDint11订单编号
ProductIDint11产品编号
UnitPricedecimal10,4单位价格
Quantitysmallint2数量
Discountdouble8,0折扣

orders表:

列名数据类型长度主码说明
OrderIDint11订单编号
CustomerIDvarchar5顾客编号
EmployeeIDint11员工编号
OrderDatedatetime,订购日期
RequiredDatedatetime,预计到达日期
ShippedDatedatetime,发货日期
ShipViaint11运货商
Freightdecimal10,4运费
ShipNamevarchar40货主姓名
ShipAddressvarchar60货主地址
ShipCityvarchar15所在城市
ShipRegionvarchar15区域
ShipPostalCodevarchar10邮政编码
ShipCountryvarchar15所在国家

表样例

orderdetails表:

OrderIDProductIDUnitPriceQuantityDiscount
102481114.0000120
10248429.8000100
102487234.800050
102491418.600090
102495142.4000400
10250417.7000100
102505142.4000350
102506516.8000150
102512216.800060
102515715.6000150

orders表:

OrderIDCustomerIDEmployeeIDOrderDateRequiredDateShippedDateShipViaFreightShipNameShipAddressShipCityShipRegionShipPostalCodeShipCountry
10248VINET51996/7/4 00:00:001996/8/1 00:00:001996/7/16 00:00:00332.3800Vins et alcools Chevalier59 rue de l-AbbayeReims51100France
10249TOMSP61996/7/5 00:00:001996/8/16 00:00:001996/7/10 00:00:00111.6100Toms SpezialittenLuisenstr. 48Mnster44087Germany
10250HANAR41996/7/8 00:00:001996/8/5 00:00:001996/7/12 00:00:00265.8300Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10251VICTE31996/7/8 00:00:001996/8/5 00:00:001996/7/15 00:00:00141.3400Victuailles en stock2, rue du CommerceLyon69004France
10252SUPRD41996/7/9 00:00:001996/8/6 00:00:001996/7/11 00:00:00251.3000Suprmes dlicesBoulevard Tirou, 255CharleroiB-6000Belgium
10253HANAR31996/7/10 00:00:001996/7/24 00:00:001996/7/16 00:00:00258.1700Hanari CarnesRua do Pao, 67Rio de JaneiroRJ05454-876Brazil
10254CHOPS51996/7/11 00:00:001996/8/8 00:00:001996/7/23 00:00:00222.9800Chop-suey ChineseHauptstr. 31Bern3012Switzerland
10255RICSU91996/7/12 00:00:001996/8/9 00:00:001996/7/15 00:00:003148.3300Richter SupermarktStarenweg 5Genve1204Switzerland
10256WELLI31996/7/15 00:00:001996/8/12 00:00:001996/7/17 00:00:00213.9700Wellington ImportadoraRua do Mercado, 12ResendeSP08737-363Brazil
10257HILAA41996/7/16 00:00:001996/8/13 00:00:001996/7/22 00:00:00381.9100HILARION-AbastosCarrera 22 con Ave. Carlos Soublette #8-35San CristbalTchira5022Venezuela

输出样例:

OrderIDProductIDUnitPriceQuantityDiscount
102481116.1000120
102484211.2700100
102487240.020050
102491418.600090
102495142.4000400
10250418.8550100
102505148.7600350
102506519.3200150
102512219.320060
102515717.9400150
UPDATE 
    orderdetails
SET 
    UnitPrice = UnitPrice * 1.15
WHERE 
    OrderID in(
	SELECT 
        OrderID
	FROM 
        orders
	WHERE 
        Freight>30
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小羊 : )

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值