念_长征
念_长征
全部文章
分类
归档
标签
去牛客网
登录
/
注册
念_长征的博客
全部文章
(共166篇)
题解 | 灵活使用sum()统计函数
# 使用sum()统计未作答完试卷次数,可理解为产生了一个新的列放入sum括号里面的条件判断值后再加和 select count(*) total_pv, sum(submit_time is not null) complete_pv, (select count(distinct exam_id...
2023-12-23
0
156
题解 | #更新表中记录-update关键字
# 更新表的基本语法:update 表名 set 列名=值 where 筛选条件 update exam_record set submit_time='2099-01-01 00:00:00', score=0 where submit_time is null and datediff('202...
2023-12-23
0
167
题解 | 子查询-未完成率较高的50%用户近三个月答卷情况
# 查询有SQL试卷答题记录的用户的id号、等级和其未完成率(只需关注有答题记录的SQL试卷,使用内连接) select u.uid, u.level, avg(submit_time is null) incomplete_rate from examination_info ei join ex...
2023-12-21
0
237
题解 | #插入记录-insert into#
insert into exam_record(uid, exam_id, start_time, submit_time, score) values(1001, 9001, '2021-09-01 22:11:12', '2021-09-01 23:01:12', 90), (1002, 900...
2023-12-21
0
182
题解 |连接条件和筛选条件的灵活使用
# 查询每张sql试卷发布当天,五级以上的作答用户人数和平均分 select ei.exam_id, count(distinct er.uid) uv, round(avg(score),1) avg_score from examination_info ei left join exam_re...
2023-12-21
0
185
题解 | #纠错4#
SELECT cust_name, cust_contact, cust_email FROM Customers WHERE cust_state = 'MI' UNION SELECT cust_name, cust_contact, cust_email FROM Customers...
2023-12-21
0
173
题解 | 使用union联合查询时默认返回的字段名
# 由于涉及到的两表之间无直接的连接关系,要合并结果使用union # union联合查询默认返回的字段名是第一条查询语句的字段名,因此排序时要注意使用prod_name字段 select prod_name from Products union select * from Customers ...
2023-12-21
0
179
题解 | #将两个 SELECT 语句结合起来(一)#
# 将两个查询语句结果合并,使用到union select * from OrderItems where quantity=100 union select * from OrderItems where prod_id like 'BNBG%' order by prod_id;
2023-12-21
0
127
题解 | #列出供应商及其可供产品的数量#
select v.vend_id, count(prod_id) prod_num from Vendors v left join Products p on v.vend_id=p.vend_id group by v.vend_id order by v.vend_id;
2023-12-21
0
177
题解 | #返回产品名称和每一项产品的总订单数#
# 需要注意的是,count()函数自动忽略null值,当count的字段全为null值时,则计数为0 select prod_name, count(order_num) orders from Products p left join OrderItems o on p.prod_id=o.pr...
2023-12-21
0
126
首页
上一页
8
9
10
11
12
13
14
15
16
17
下一页
末页