0
点赞
收藏
分享

微信扫一扫

MySQL曹操外卖项目--数据库设计

雨鸣静声 2022-03-24 阅读 126
mysql

 

 

 

 

 

-- 查询所有外卖商品编号、名称、定价、折扣、分类编号、商家编号、评分、描述、包装费
SELECT * FROM goods
-- 查询“川湘菜”类型的所有外卖商品信息
SELECT * FROM goods where storeId=(SELECT storeId FROM store where storeName='川湘菜')
-- 查询出所有包含“大盘鸡”标题的外卖商品
SELECT * FROM goods where title LIKE'%大盘鸡%'
-- 查询所有评分为5并且描述中含有麻辣内容的外卖商品
SELECT * from goods where roat=5 and description LIKE'%麻辣%'
-- 查询编号为24的外卖商品编号、名称、定价、折扣、分类编号、商家编号、评分、描述、包装费
SELECT * from goods where goodsId=24
-- 查询外卖商品销售数量前10名的外卖商品编号
SELECT goodsID from orderdetails ORDER BY qty DESC LIMIT 10
SELECT * FROM goods where goodsId in(SELECT goodsID from orderdetails ORDER BY qty DESC)
-- 查询顾客姓名为黄雅玲的所有历史订单信息
SELECT * FROM orders where custName='黄雅玲'
-- 查新人均消费在30-50之间并且是川湘菜的外卖商品
SELECT storeId from store where personSpending BETWEEN 30 and 50
SELECT * FROM goods where cateId=6 and  storeId in(SELECT storeId from store where personSpending BETWEEN 30 and 50)
-- 查询所有每种类型的外卖商品的总销售额
SELECT a.goodsId,b.orederID,c.unitPrice as'销售总额' FROM goods a,orders b,orderdetails c WHERE a.goodsId=c.goodsID and b.orederID=c.orderID
-- 查询今天的外卖总销售额
SELECT SUM(unitPrice) FROM orderdetails
-- 统计每个类别的外卖商品数量
SELECT a.CateName as '外卖类型',b.title as'外卖名称',c.qty as'销量' FROM category a,goods b,orderdetails c where a.CateID=b.cateId and b.goodsId=c.goodsID
-- 查询出所有‘张三大盘鸡’的外卖商品
SELECT * FROM goods where title='张三大盘鸡'
-- 国庆期间外卖商品打折,所有外卖商品一律8.5折,特色小吃类外卖商品7.5折销售
UPDATE goods SET discount=0.85
UPDATE goods SET discount=0.75 where cateId=7
-- Tom最近订购的一个订单编号为‘20220220001’,这个订单已经收货,需要修改订单的状态
UPDATE orders SET orderStatus='已收货' where orderNo=20220220001
-- Tom 更改密码
UPDATE customers SET loginPwd='Tom_Love$book' where custName='Tom'
-- 查询所有已发货的订单,显示订单编号、订单日期、收货人姓名和电话
SELECT orderNo,orderDate,custName,custPhone FROM orders where orderStatus='已发货'
-- 查询已完成的订单的订单明细,显示订单日期、订购的外卖名称、订购数量、订购单价
SELECT a.orderDate,b.title,c.qty,c.unitPrice from orders a,goods b,orderdetails c 
where a.orederID=c.orderID and b.goodsId=c.goodsID
-- 查询出orderno为“20210508004”的收货人姓名、地址和电话
SELECT orderNo,custAddress,custPhone from orders where orderNo=20210508004
-- 查询出收货人电话以‘188’开头的客户有几人
SELECT COUNT(custPhone) FROM orders WHERE custPhone LIKE'188%'
-- 查询收货地址在‘二七广场’地区的有几人
SELECT COUNT(custAddress) FROM orders where custAddress='二七广场'
-- 查询出账单金额最高的订单的收货人姓名和电话
SELECT MAX(orderPrice) FROM orders
SELECT custName,custPhone FROM orders where orderPrice=(SELECT MAX(orderPrice) FROM orders )
-- 在orders表中获取所有的收货地址,以及每个收货地址购物的次数
SELECT custAddress,COUNT(custAddress) as '购物次数' FROM orders GROUP BY custAddress;
-- 查询出收货地址为“北京市和平东路四段32号”的所购外卖商品的商品名收货人的姓名,地址,商品信息,价格,数量商品分类
SELECT d.custName,d.custAddress,a.Title,a.unitPrice,b.qty,c.CateName FROM goods a,orderdetails b,category c,orders d
where a.goodsId=b.goodsID and a.cateId=c.CateID and b.orderID=d.orederID and d.custAddress='北京市和平东路四段32号'
-- 请查询出收货地址为“北京市和平东路四段32号”的所购外卖商品的商品名收货人的姓名,地址,商品信息,价格,数量商品分类,并按照外卖商品的单价以降序排列
SELECT d.custName,d.custAddress,a.Title,a.unitPrice,b.qty,c.CateName FROM goods a,orderdetails b,category c,orders d
where a.goodsId=b.goodsID and a.cateId=c.CateID and b.orderID=d.orederID and d.custAddress='北京市和平东路四段32号' ORDER BY a.unitPrice DESC
-- 查询所有外卖商品中单价最高的外卖商品类别
SELECT b.CateName FROM goods a,category b WHERE a.cateId=b.cateID and a.unitPrice=(SELECT max(unitPrice) FROM goods)
-- 查询销量(销售金额)最高的一天。
SELECT orderDate,max(orderPrice) as '最高金额' FROM orders
-- 统计注册外卖商品中每个商品类别各有多少种商品。
SELECT cateId,COUNT(*) AS '各有几种' FROM goods GROUP BY cateId
-- 大客户查询,查询出外卖订单总价最多的客户名
SELECT custName,MAX(orderPrice)AS '订单总价' FROM orders
SELECT custName FROM orders WHERE orderPrice=(SELECT max(orderPrice) FROM orders)
-- 查询出每个商品类别中外卖商品的最高价格,最低价格和平均价格
SELECT MAX(unitPrice)AS '最高价格',MIN(unitPrice)AS '最低价格',AVG(unitPrice)AS '平均价格' FROM goods


举报

相关推荐

0 条评论