mysql学习笔记(五)—— 11-20题练习讲解

1. 修改Customer表中客户姓名是“李立”的联系方式为15119280983

UPDATE customer SET  phone = 15119280983 where custname='李立';

2. 查询出能够容纳12人以上的最合适的包厢信息。

select * from box where boxcapacity >= 12 and boxstatus = '空闲'

3. 查询可容纳人数最多的包厢信息。

select * from box where boxcapacity=(select max(boxcapacity) from box);
select * from box ORDER BY boxcapacity desc LIMIT 1;

第一句是将一条查询语句的结果作为参数加进主句的where里做判断

这是两种方法,更推荐第二种方法

4. 查询容纳人数按照从多到少排第三的包厢信息。

select * from box 
ORDER BY boxcapacity desc 
limit 2,1;

select box.* from (select * from box ORDER BY boxcapacity desc limit 3) box 
order by box.boxcapacity asc limit 1;

limit 2,1 :第二行的位置取一行

5. 查询所有会员的平均年龄。

select Round(AVG(year(now())-year(birthday))) as avgAge 
from customer 
where ismembership = "是";

year:获取年份函数
AVG:平均函数
Round:四舍五入函数

6. 查询非会员中年大于30周岁的人员信息。

select * from customer 
where ismembership = "否" and (year(now())-year(birthday)) > 30;

7. 查询所有客户的姓名,结果不包含重复记录。

select custname from customer GROUP BY custname;

group by对客户名称做了分组

8 将所有客户的姓名中的“张”替换为“章”。

select replace(sname,'张','章') from student;

replace:替换字方法

9 查询包厢容量大于等于30的包厢信息的包厢名称和底价。

select boxname a,lowestprice b from box where boxcapacity>=30;

a,b:给比较长的字段起个外号

10 将结果中列的标题分别指定为“包厢名”和“最低价”。

select boxname as 包厢名,MIN(lowestprice) as 最低价 from box;

MIN:最小值
as:修改当前字段展示字段名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值