news 2026/9/21 16:25:16

《Mysql数据库应用》 第2版 郭文明 实验7 “网上商城”项目实验核心操作与思路解析

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
《Mysql数据库应用》 第2版 郭文明 实验7 “网上商城”项目实验核心操作与思路解析

汽车用品网上商城系统概述:

汽车用品网上商城数据库由以下8张表组成:

autoparts,category,client,clientkind,comment,order,order_has_autoparts,shoppingcart,分别为汽车配件表、商品类别表、用户表、用户类别表、评论表、订单表、订单明细表、购物车配件表。

功能结构图:

页面展示形式:

1汽车用品网上商城前台功能

【实验7-1】主页中查询汽车配件对应的SQL操纵,编写一存储过程,实现查询特定汽车配件信息的功能。

【实验7-2】操作购物车,往购物车表中添加记录,并对购物车中某一条记录作删除操作。

【实验7-3】提交订单,编写一存储过程,给定会员编号、收货人姓名、收货人地址后在订单表中生成订单信息,同时将购物车中已有的该会员的购物记录追加到订单明细表中。

代码如下:

CREATE DEFINER=`root`@`localhost` PROCEDURE `submit_order`(in scid int,in sname varchar(50),in saddr text) BEGIN declare sapid int; declare snum int; declare sprice decimal(5,2); declare sgood_price decimal(5,2); declare sweight int; declare stime datetime; declare soid int; ​​​​​​​select autoparts_apid into sapid from shopping.shoppingcart where client_cid=scid; select `number` into snum from shopping.shoppingcart where client_cid=scid; select price into sprice from autoparts where apid=sapid; select weight*snum into sweight from autoparts where apid=sapid; set sgood_price=sprice*snum; set sweight=sweight*snum; set stime=now(); insert into `order`(`status`,order_date,client_cid,goods_price,carriage_price,total_price,total_weight,`name`,telephone,address_aid,pay_type) values("已付款",stime,scid,sgood_price,0,sgood_price,sweight,sname,"13896582356",saddr,"微信支付"); select oid into soid from `order` where order_date=stime; insert into order_has_autoparts(autoparts_apid,order_oid,deal_price,`number`) values(sapid,soid,sprice,snum); END

2汽车用品网上商城后端功能

【实验7-4】管理会员,对会员表中数据进行增删改查。

【实验7-5】管理商品,对汽车配件表中数据进行增删改查。

【实验7-6】管理类别,对商品类别表进行增删改查。

​​​​​​​

【实验7-7】管理订单,修改订单表中的状态字段。

【实验7-8】查询统计,通过查询视图或者基表等手段,完成如下统计:本月销售汽车配件总数量、销售总金额、订单总数量、发生订单的会员数;最大的订单、最小的订单、消费金额最多的会员、消费金额最少的会员;卖的最好的汽车配件、卖得最差的汽车配件。

本月销售汽车配件总数量:

本月销售总金额:

本月订单总数量:

本月发生订单的会员数:

本月最大的订单:

本月最小的订单:

本月消费金额最多的会员:

本月消费金额最少的会员:

本月卖的最好的汽车配件:

本月卖得最差的汽车配件:

3.数据库备份与恢复

【实验7-9】对Shopping数据库进行备份

4.数据导入导出

【实验7-10】以文本格式导出汽车配件表,在Excel下完成汽车配件表的编辑(可选),将编辑后的汽车配件信息导入到Shopping数据库汽车配件表中。

导出汽车配件表:

导入汽车配件表:

【实验7-1】主页中查询汽车配件对应的SQL操纵,编写一存储过程,实现查询特定汽车配件信息的功能。
create procedure see_autoparts(in pname varchar(20))
begin
select * from shopping.autoparts where apname=pname;
end
call see_autoparts("轮胎")
【实验7-2】操作购物车,往购物车表中添加记录,并对购物车中某一条记录作删除操作。
insert into shoppingcart(autoparts_apid,client_cid,`number`,add_time) values(10,12,1,now());
delete from shoppingcart where autoparts_apid=10 and client_cid=12;
【实验7-3】提交订单,编写一存储过程,给定会员编号、收货人姓名、收货人地址后在订单表中生成订单信息,同时将购物车中已有的该会员的购物记录追加到订单明细表中。
CREATE DEFINER=`root`@`localhost` PROCEDURE `submit_order`(in scid int,in sname varchar(50),in saddr text)
BEGIN
declare sapid int;
declare snum int;
declare sprice decimal(5,2);
declare sgood_price decimal(5,2);
declare sweight int;
declare stime datetime;
declare soid int;

select autoparts_apid into sapid from shopping.shoppingcart where client_cid=scid;
select `number` into snum from shopping.shoppingcart where client_cid=scid;
select price into sprice from autoparts where apid=sapid;
select weight*snum into sweight from autoparts where apid=sapid;
set sgood_price=sprice*snum;
set sweight=sweight*snum;
set stime=now();
insert into `order`(`status`,order_date,client_cid,goods_price,carriage_price,total_price,total_weight,`name`,telephone,address_aid,pay_type)
values("已付款",stime,scid,sgood_price,0,sgood_price,sweight,sname,"13896582356",saddr,"微信支付");
select oid into soid from `order` where order_date=stime;
insert into order_has_autoparts(autoparts_apid,order_oid,deal_price,`number`) values(sapid,soid,sprice,snum);
END

【实验7-4】管理会员,对会员表中数据进行增删改查。
insert into shopping.client(cid,cname,`password`,phone_number,email,createtime,ckind) values(25,"唐三",'111111',"15888886666","89895678@qq.com",now(),23);
delete from shopping.client where cid=25;
update shopping.client set cname="萧炎" where cid=24;
select * from shopping.client where cid=24;
【实验7-5】管理商品,对汽车配件表中数据进行增删改查。
insert into shopping.autoparts(apname,is_sale,price,secondclass_scid) values("轮胎",0,200,1);
delete from shopping.autoparts where apid=10;
update shopping.autoparts set apname="发动机" where apid=11;
select * from shopping.autoparts;
【实验7-6】管理类别,对商品类别表进行增删改查。
insert into shopping.category(`name`) values("轮胎系列");
delete from shopping.category where category_id=102;
update shopping.category set name="传动系统" where category_id=101;
select * from shopping.category;
【实验7-7】管理订单,修改订单表中的状态字段。
update shopping.order set `status`="已退款" where oid=13;
【实验7-8】查询统计,通过查询视图或者基表等手段,完成如下统计:本月销售汽车配件总数量、销售总金额、订单总数量、发生订单的会员数;最大的订单、最小的订单、消费金额最多的会员、消费金额最少的会员;卖的最好的汽车配件、卖得最差的汽车配件。
select month(now()) as "本月",sum(sum_number) as "销售汽车配件总数量" from shopping.everyday_everyparts where month(everyday) =month(now());
select month(now()) as "本月",sum(income) as "销售总金额" from shopping.everyday where month(riqi)=month(now());
select month(now()) as "本月",sum(order_total) as "订单总数量" from shopping.everyday where month(riqi)=month(now());
select count(distinct cid) as "发生订单的会员数" from shopping.client_order;
select * from shopping.everyday_everyparts order by stotal_price desc limit 0,1;
select * from shopping.everyday_everyparts order by stotal_price asc limit 0,1;
select cid,sum(total_price) as stotal from shopping.client_order group by cid order by stotal desc limit 0,1;
select cid,sum(total_price) as stotal from shopping.client_order group by cid order by stotal asc limit 0,1;
select autoparts_apid,sum(sum_number) as num_total from shopping.everyday_everyparts group by autoparts_apid order by num_total desc limit 0,1;
select apid as "没有产生过订单的配件编号" from autoparts where apid not in(select autoparts_apid from order_has_autoparts);
【实验7-10】以文本格式导出汽车配件表,在Excel下完成汽车配件表的编辑(可选),将编辑后的汽车配件信息导入到Shopping数据库汽车配件表中。
use shopping;
select * from autoparts into outfile "d:/backup/autoparts.txt"
load data infile "d:/backup/autoparts.txt" replace into table shopping.autoparts;


【实验7-1】主页中查询汽车配件对应的SQL操纵,编写一存储过程,实现查询特定汽车配件信息的功能。 create procedure see_autoparts(in pname varchar(20)) begin select * from shopping.autoparts where apname=pname; end call see_autoparts("轮胎") 【实验7-2】操作购物车,往购物车表中添加记录,并对购物车中某一条记录作删除操作。 insert into shoppingcart(autoparts_apid,client_cid,`number`,add_time) values(10,12,1,now()); delete from shoppingcart where autoparts_apid=10 and client_cid=12; 【实验7-3】提交订单,编写一存储过程,给定会员编号、收货人姓名、收货人地址后在订单表中生成订单信息,同时将购物车中已有的该会员的购物记录追加到订单明细表中。 CREATE DEFINER=`root`@`localhost` PROCEDURE `submit_order`(in scid int,in sname varchar(50),in saddr text) BEGIN declare sapid int; declare snum int; declare sprice decimal(5,2); declare sgood_price decimal(5,2); declare sweight int; declare stime datetime; declare soid int; select autoparts_apid into sapid from shopping.shoppingcart where client_cid=scid; select `number` into snum from shopping.shoppingcart where client_cid=scid; select price into sprice from autoparts where apid=sapid; select weight*snum into sweight from autoparts where apid=sapid; set sgood_price=sprice*snum; set sweight=sweight*snum; set stime=now(); insert into `order`(`status`,order_date,client_cid,goods_price,carriage_price,total_price,total_weight,`name`,telephone,address_aid,pay_type) values("已付款",stime,scid,sgood_price,0,sgood_price,sweight,sname,"13896582356",saddr,"微信支付"); select oid into soid from `order` where order_date=stime; insert into order_has_autoparts(autoparts_apid,order_oid,deal_price,`number`) values(sapid,soid,sprice,snum); END 【实验7-4】管理会员,对会员表中数据进行增删改查。 insert into shopping.client(cid,cname,`password`,phone_number,email,createtime,ckind) values(25,"唐三",'111111',"15888886666","89895678@qq.com",now(),23); delete from shopping.client where cid=25; update shopping.client set cname="萧炎" where cid=24; select * from shopping.client where cid=24; 【实验7-5】管理商品,对汽车配件表中数据进行增删改查。 insert into shopping.autoparts(apname,is_sale,price,secondclass_scid) values("轮胎",0,200,1); delete from shopping.autoparts where apid=10; update shopping.autoparts set apname="发动机" where apid=11; select * from shopping.autoparts; 【实验7-6】管理类别,对商品类别表进行增删改查。 insert into shopping.category(`name`) values("轮胎系列"); delete from shopping.category where category_id=102; update shopping.category set name="传动系统" where category_id=101; select * from shopping.category; 【实验7-7】管理订单,修改订单表中的状态字段。 update shopping.order set `status`="已退款" where oid=13; 【实验7-8】查询统计,通过查询视图或者基表等手段,完成如下统计:本月销售汽车配件总数量、销售总金额、订单总数量、发生订单的会员数;最大的订单、最小的订单、消费金额最多的会员、消费金额最少的会员;卖的最好的汽车配件、卖得最差的汽车配件。 select month(now()) as "本月",sum(sum_number) as "销售汽车配件总数量" from shopping.everyday_everyparts where month(everyday) =month(now()); select month(now()) as "本月",sum(income) as "销售总金额" from shopping.everyday where month(riqi)=month(now()); select month(now()) as "本月",sum(order_total) as "订单总数量" from shopping.everyday where month(riqi)=month(now()); select count(distinct cid) as "发生订单的会员数" from shopping.client_order; select * from shopping.everyday_everyparts order by stotal_price desc limit 0,1; select * from shopping.everyday_everyparts order by stotal_price asc limit 0,1; select cid,sum(total_price) as stotal from shopping.client_order group by cid order by stotal desc limit 0,1; select cid,sum(total_price) as stotal from shopping.client_order group by cid order by stotal asc limit 0,1; select autoparts_apid,sum(sum_number) as num_total from shopping.everyday_everyparts group by autoparts_apid order by num_total desc limit 0,1; select apid as "没有产生过订单的配件编号" from autoparts where apid not in(select autoparts_apid from order_has_autoparts); 【实验7-10】以文本格式导出汽车配件表,在Excel下完成汽车配件表的编辑(可选),将编辑后的汽车配件信息导入到Shopping数据库汽车配件表中。 use shopping; select * from autoparts into outfile "d:/backup/autoparts.txt" load data infile "d:/backup/autoparts.txt" replace into table shopping.autoparts;
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/21 13:49:01

告别烦人黑窗口:3分钟学会用RunHiddenConsole让Windows程序后台运行

告别烦人黑窗口:3分钟学会用RunHiddenConsole让Windows程序后台运行 【免费下载链接】RunHiddenConsole Hide console window for windows programs 项目地址: https://gitcode.com/gh_mirrors/ru/RunHiddenConsole 你是否曾经为那些顽固的控制台窗口感到烦恼…

作者头像 李华
网站建设 2026/9/21 3:03:21

Steamless终极指南:专业级SteamStub DRM移除工具完整解析

Steamless终极指南:专业级SteamStub DRM移除工具完整解析 【免费下载链接】Steamless Steamless is a DRM remover of the SteamStub variants. The goal of Steamless is to make a single solution for unpacking all Steam DRM-packed files. Steamless aims to …

作者头像 李华
网站建设 2026/9/22 1:37:57

Venera漫画阅读器:5分钟快速上手完整指南

Venera漫画阅读器:5分钟快速上手完整指南 【免费下载链接】venera A comic app 项目地址: https://gitcode.com/gh_mirrors/ve/venera 还在为漫画阅读体验不佳而烦恼吗?Venera漫画阅读器为您带来全平台覆盖的优质漫画阅读解决方案。这款跨平台漫画…

作者头像 李华
网站建设 2026/9/21 22:39:53

Python环境管理终极指南:实现多版本无缝切换

Python环境管理终极指南:实现多版本无缝切换 【免费下载链接】pyenv Simple Python version management 项目地址: https://gitcode.com/GitHub_Trending/py/pyenv 在Python开发中,不同项目往往需要不同的Python版本支持。传统方式下,…

作者头像 李华
网站建设 2026/9/21 13:09:54

基于Wan2.2-T2V-A14B构建商用级视频生成系统的最佳实践

基于Wan2.2-T2V-A14B构建商用级视频生成系统的最佳实践 在短视频内容爆炸式增长的今天,企业对高质量视频的渴求从未如此强烈。但现实是:一支30秒广告片仍需数天拍摄、反复剪辑,成本动辄上万元;电商平台每天上新成千上万商品&#…

作者头像 李华