MySQL数据库实验三 MySQL查询

一、实验项目:

MySQL查询。

二、实验目的

掌握MySQL的查询操作。

三、实验内容

(一):

1、查询lineitem表中商品编号(productid)和单价(unitprice),要求消除重复行。

select distinct productid, unitprice from lineitem;

2、计算lineitem表中每条记录的商品金额。

select unitprice*quantity from lineitem;

3、显示orders表单笔高于200元的客户号(userid)、成交金额(totalprice)和订单状态(status)。

select userid,totalprice,status from orders where totalprice >200;

4、查询orders表中2013年4月份的所有订单。

select * from orders where year(orderdate)=2013 and month(orderdate)=4;

5、查询account表中姓吴的客户信息。

select * from account where fullname like "吴%";

6、查询orders表成交总额200元-500元的订单信息。

select * from orders where totalprice between 200 and 500;

7、查询product表中商品编号(productid)倒数第4个标号为W的商品信息。

select * from product where productid like "%W___";

8、将orders表按客户号从小到大排序,客户号相同的按订购日期从大到小排序。

select * from orders order by userid,orderdate desc;

9、按性别统计客户人数。

select sex,count(*) from account group by sex;

10、显示lineitem表中商品的购买总数量超过2件的商品编号和购买总数量,并按购买总数量从小到大排序。

select productid,sum(quantity) from lineitem 
group by productid having sum(quantity)>2
order by sum(quantity);

(二):

1、查询lineitem表中订单编号、商品名称和购买数量。

select orderid,quantity,name from product,lineitem 
where lineitem.productid=product.productid;

2、显示orders表单笔高于300元的客户名和订单总价。

select fullname,totalprice  from orders,account
where totalprice>300 and orders.userid=account.userid;

3、查询“刘晓和”的基本情况和订单情况。

select * from orders,account
where fullname='刘晓和' and orders.userid=account.userid;

4、统计2013年5月以前订购了商品的女客户姓名和订购总额。

select sum(totalprice),fullname  from orders,account
where sex= '女' and orderdate<'20130501' and orders.userid=account.userid
group by account.userid;

5、查找购买了商品编号为FI-SW-02的订单号、客户号和订购日期。

select orders.orderid,userid,orderdate  from orders,lineitem
where productid='FI-SW-02'and orders.orderid=lineitem.orderid;

6、查询已经被购买过的商品信息。(使用IN关键字的子查询实现)

SELECT * FROM product WHERE productid IN(SELECT productid FROM lineitem);

7、查询已经被购买过的商品信息。(使用EXISTS关键字的子查询实现)

SELECT * FROM product WHERE EXISTS 
(SELECT * FROM lineitem WHERE lineitem.productid=product.productid);

8、查询比类别编号为01的最低库存量都高的全部商品信息。(使用子查询实现)

SELECT * FROM product WHERE qty > ANY 
(SELECT qty FROM product WHERE catid= '01');

9、查询比类别编号为01的最高库存量都高的全部商品信息。(使用子查询实现)

SELECT * FROM product WHERE qty > ALL 
(SELECT qty FROM product WHERE catid= '01');

10、查询购买了天使鱼的客户名称。

select fullname from account,product,orders,lineitem
Where orders.userid=account.userid and orders.orderid=lineitem.orderid
And lineitem.productid=product.productid and name='天使鱼';
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Meteor.792

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

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

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

打赏作者

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

抵扣说明:

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

余额充值