高频SQL50题 第四天 | 1251. 平均售价、620. 有趣的电影、1075. 项目员工 I、1633. 各赛事的用户注册率

知识点导览:日期大小比较;ifnull(字段,默认值)函数;取余操作;字符串比较like;逆序desc

1251. 平均售价

题目链接:https://leetcode.cn/problems/average-selling-price/description/?envType=study-plan-v2\&envId=sql-free-50

状态:已完成

考点

  • 判断日期是否位于某个区间内,可以使用 > = >= >=和 < = <= <=计算
  • i f n u l l ( 字段,默认值 ) ifnull(字段,默认值) ifnull(字段,默认值)可以将字段中的null替换为默认值
sql 复制代码
select Prices.product_id, ifnull(round(sum(price*units) / sum(units), 2), 0) as average_price
from Prices left join UnitsSold
on Prices.product_id = UnitsSold.product_id and UnitsSold.purchase_date >= Prices.start_date and UnitsSold.purchase_date <= Prices.end_date
group by product_id

620. 有趣的电影

题目链接:https://leetcode.cn/problems/not-boring-movies/?envType=study-plan-v2\&envId=sql-free-50

状态:已完成

考点

  • 取余操作 %
  • 字符串比较操作 like,not like
  • 逆序排序 order by XXX desc
sql 复制代码
select *
from cinema
where id % 2 = 1 and description not like 'boring'
order by rating desc

1075. 项目员工 I

题目链接:https://leetcode.cn/problems/project-employees-i/?envType=study-plan-v2\&envId=sql-free-50

状态:已完成

考点:无,均为重复考点

sql 复制代码
select project_id, round(sum(experience_years) / count(*), 2) as average_years
from Project join Employee
on Project.employee_id = Employee.employee_id
group by project_id

1633. 各赛事的用户注册率(*)

题目链接:https://leetcode.cn/problems/percentage-of-users-attended-a-contest/description/?envType=study-plan-v2\&envId=sql-free-50

状态:需二刷,想了好久怎么通过连接解决,最后还是没想到

考点:子查询获取用户总数,作为新的一列num,通过连接操作加入Register表中

sql 复制代码
select contest_id, round(count(*) / num * 100, 2) as percentage
from Register join (select count(*) as num from Users) as Table1
group by contest_id
order by percentage desc, contest_id
相关推荐
醉颜凉2 小时前
KingbaseES日期格式化:MySQL date_format函数的迁移指南
mysql·date_format·kingbasees·数据库兼容·函数迁移
醉颜凉2 小时前
MySQL 8 忘记 root 密码?这两种方法帮你轻松解决
数据库·mysql·adb
刃神太酷啦2 小时前
Linux 系统 MySQL 完整安装配置教程:从卸载 MariaDB 到优化 my.cnf----《Hello MySQL!》(1)
android·linux·c语言·c++·mysql·leetcode·mariadb
xxwl5853 小时前
MySQL 基础学习笔记
数据库·mysql
Rain的Java大神之路3 小时前
PC版网站被狂刷怎么处理
java·数据库·redis·后端·mysql·web安全·运维开发
程序员-Benothing5 小时前
MySQL 中的 MVCC 是什么?如果没有 MVCC,会有什么影响?
数据库·mysql
程序员-Benothing6 小时前
MySQL 中的事务隔离级别有哪些?默认的事务隔离级别是什么?为什么选择这个级别?
数据库·mysql
小林ixn8 小时前
从零设计一个博客系统的数据库:表结构、索引与约束的实战思考
数据库·后端·mysql
GreatSQL社区9 小时前
少敲一个字母,GreatSQL 对所有查询“已读不回”
数据库·mysql·greatsql
qq_3391911410 小时前
mysql磁盘占用排查,mysql存储空间占比统计,mysql判断哪张表占用磁盘空间大
数据库·mysql