Austin_zhai
Austin_zhai
全部文章
分类
题解(18)
归档
标签
去牛客网
登录
/
注册
Austin_zhai的博客
全部文章
(共14篇)
题解 | #得分不小于平均分的最低分#
计算不得小于平均分的最低分数,要点就在于如何将分数与平均分做比较,此处比较推荐在where字句中进行条件判断,虽然在where子句中使用select查询会降低查询效率,但只要数据量不大,也是可以使用的。 select min(e1.score) min_score_over_avg from e...
Mysql
2022-07-18
0
255
题解 | #统计作答次数#
乍一看是挺简单的一题,好像只需要计算出各个字段的count值即可,这里有一个坑,就是当没完成交卷的次数不计入计数的时候,三个字段就无法通过where去进行筛选,这里使用if对单个需要不计算非交卷的个数进行排除即可。 select count(*) total_pv, count(submit_ti...
Mysql
2022-07-18
0
253
题解 | #SQL类别高难度试卷得分的截断平均值#
求截断平均值,按照题目的要求我们直接去掉exam_id为9001中的最高值和最低值再求平均数即可。 select tag,difficulty,t.clip_avg_score from (select round(((sum(score)-max(score)-min(score))/(cou...
Mysql
2022-07-16
0
266
题解 | #修改表#
根据要求对指定位置增加字段、变更字段名称及属性、修改默认值与备注进行操作 alter table user_info add column school varchar(15) after level, change job profession varchar(10), modify achie...
Mysql
2022-07-15
0
256
题解 | #创建一张新表#
根据题目所提供的每个字段的信息,创建对应的字段、类型、限制、默认值、注释 create table if not exists user_info_vip( id int(11) primary key auto_increment comment '自增ID', uid int...
Mysql
2022-07-15
0
284
题解 | #删除记录(一)#
这里的记录有一条是时差在4分59,故不适合使用timediff进行精确判断,此处使用时间戳判断更为适合 delete from exam_record where timestampdiff(minute,start_time,submit_time)<5 and score<60;
Mysql
2022-07-14
0
185
题解 | #返回每个顾客不同订单的总金额#
通过提示使用sum进行总订单额的计算,并将结果作为表带入到查询中进行排序筛选 select cust_id, t.total_ordered from (select sum(item_price*quantity) total_ordered, order_num from OrderI...
Mysql
2022-07-13
0
264
题解 | #返回 prod_id 为 BR01 的电子邮件#
这里使用较为简单粗暴的三表连接后再进行条件筛选 select cust_email from Customers c join Orders o on c.cust_id=o.cust_id join OrderItems o2 on o.order_num=o2.order_num whe...
Mysql
2022-07-13
0
217
题解 | #顾客登录名#
首先使用left进行用户名与地名的字段切割,再使用concat进行拼接,最后使用upper拼接内容大写化。 select cust_id, cust_name, upper(concat(left(cust_name,2),left(cust_city,3))) user_login from Cu...
Mysql
2022-07-11
0
230
题解 | #检索产品名称和描述(三)#
使用like和and将需要模糊匹配的字符放入即可,这里需要注意的是使用头尾%来声明匹配多个字符。 select prod_name,prod_desc from Products where prod_desc like '%carrots%' and prod_desc like ...
Mysql
2022-07-11
1
308
首页
上一页
1
2
下一页
末页