当前位置: 首页 > news >正文

sql语句练习

1661. 每台机器的进程平均运行时间 - 力扣(LeetCode)

select machine_id,round(sum(if(activity_type = 'end',timestamp,-timestamp))/count(distinct process_id),3) 
as processing_time from Activity group by machine_id 

if(activity_type = 'end',timestamp,-timestamp),if条件成立则sum+timestamp,否则

sum+(-timestamp)

count(distinct process_id),统计不同id的个数

round(x,3),让x保留三位小数

577. 员工奖金 - 力扣(LeetCode)

select name,bonus from Employee f left join Bonus b on f.empId=b.empId 
where b.bonus<1000 or b.bonus is null

a left join b on a.id=b.id 会显示出对于a表各个列的结果,而加上过滤条件后对于a没有的列则会给出null值

1280. 学生们参加各科测试的次数 - 力扣(LeetCode)

select a.student_id,a.student_name,b.subject_name,count(e.subject_name) as attended_exams from
(Students a,Subjects b) left join Examinations e on a.student_id=e.student_id and e.subject_name=b.subject_name
group by  student_id, student_name,subject_name
order by student_id,student_name

三个表进行连接,使用left join以

Examinations表为基准来显示,用科目名字和学生id把三个表连接起来,根据样例结果来看,我们把学生id,学生名字,科目名字进行聚合分组,再根据id大小和名字字典序进行排列

620. 有趣的电影 - 力扣(LeetCode)

select *  from cinema where description <> 'boring' and id&1 order by rating desc

id&1表示id必须为计数,<>等同于!=


http://www.mrgr.cn/news/30502.html

相关文章:

  • Mybatis 快速入门(maven)
  • C++标准的一些特性记录:C++11的thread_local
  • 傅里叶变换的基本性质和有关定理
  • 【电路笔记】-运算放大器比较器
  • 大牛直播SDK核心音视频模块探究
  • C++的初阶模板和STL
  • 前端常用的主流框架有哪些
  • 诗文发布模板(python代码打造键盘录入诗文自动排版,MarkDown源码文本)
  • javascript中栈内存与堆内存如何理解?以及如何区分?
  • @JsonFormat 和 @DateTimeFormat 的区别
  • 将有序数组——>二叉搜索树
  • 9. 什么是 Beam Search?深入理解模型生成策略
  • Kotlin cancel CoroutineScope.launch的任务后仍运行
  • 智谱清影 -CogVideoX-2b-部署与使用,带你揭秘生成6s视频的极致体验!
  • C++初阶:STL详解(五)——vector的模拟实现
  • 华为云DevSecOps和DevOps
  • LeetCode_sql_day28(1767.寻找没有被执行的任务对)
  • Java-list集合转成前端需要的json格式
  • 【Tourism】Yuncheng(3)
  • PCL 计算点云距离