【hackerrank】Placements
题目如下:
You are given three tables: Students, Friends and Packages. Students contains two columns: ID and Name. Friends contains two columns: ID and Friend_ID (ID of the ONLY best friend). Packages contains two columns: ID and Salary (offered salary in $ thousands per month).
Write a query to output the names of those students whose best friends got offered a higher salary than them. Names must be ordered by the salary amount offered to the best friends. It is guaranteed that no two students got same salary offer.
Sample Input
Sample Output
Samantha
Julia
Scarlet
Explanation
See the following table:
Now,
- Samantha's best friend got offered a higher salary than her at 11.55
- Julia's best friend got offered a higher salary than her at 12.12
- Scarlet's best friend got offered a higher salary than her at 15.2
- Ashley's best friend did NOT get offered a higher salary than her
The name output, when ordered by the salary offered to their friends, will be:
- Samantha
- Julia
- Scarlet
解题思路:本题难度一般,涉及到三张表的联合。为了清晰易读,可以把Students和Packages做联合,查出每个学生的名字和工资,并记为结果集a;同时把Friends和Packages表做联合查询,查询每个朋友的工资,并记为结果集b;最后再对a和b做联合查询即可。
代码如下:
/*
Enter your query here.
*/
select a.S_Name from
(select s.Name as S_Name,s.ID as S_ID,p.salary as S_salary from Students s,Packages p where s.ID = p.ID) a,
(select f.ID as F_ID,p.salary as F_salary from Friends f,Packages p where f.Friend_ID = p.ID) b
where S_ID = F_ID and S_salary < F_salary order by F_salary;
【hackerrank】Placements的更多相关文章
- 【HackerRank】How Many Substrings?
https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...
- 【HackerRank】Running Time of Quicksort
题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ...
- 【hackerrank】Week of Code 30
Candy Replenishing Robot Find the Minimum Number 直接模拟 Melodious password dfs输出方案 Poles 题意:有多个仓库,只能从后 ...
- 【hackerrank】Week of Code 26
在jxzz上发现的一个做题网站,每周都有训练题,题目质量……前三题比较水,后面好神啊,而且类型差不多,这周似乎是计数专题…… Army Game 然后给出n*m,问需要多少个小红点能全部占领 解法:乘 ...
- 【HackerRank】Median
题目链接:Median 做了整整一天T_T 尝试了各种方法: 首先看了解答,可以用multiset,但是发现java不支持: 然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大 ...
- 【HackerRank】Coin on the Table
题目链接:Coin on the Table 一开始想用DFS做的,做了好久都超时. 看了题解才明白要用动态规划. 设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的 ...
- 【HackerRank】Pairs
题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ...
- 【HackerRank】Cut the tree
题目链接:Cut the tree 题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小. 暴力求解会超时. 如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a ...
- 【HackerRank】Missing Numbers
Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very pr ...
随机推荐
- java四舍五入及注意点
package com.example.newtest.test; import java.math.BigDecimal; import java.math.RoundingMode; import ...
- WinFrom控件双向绑定
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 应用安全 - 工具 - NScan - 漏洞汇总
工具介绍 Date 用途 端口服务扫描 | whois | nslookup Nscan v0.9.1 缓冲区溢出导致远程代码执行 Date 类型缓冲区溢出导致远程代码执行 影响范围 复现字符量过多 ...
- Python_ONLINE_习题集_02 函数封装
2.1 封装函数实现如下要求 例如:输入2,5 则求:2 + 22+222 + 2222+22222的和 参考答案: https://www.bilibili.com/read/cv4185619 d ...
- C语言第十一周作业
这个作业属于哪个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/ ...
- 虚拟机上首次安装Ubuntu后 root密码设置
虚拟机下安装ubuntu后root密码设置 问题描述: 在虚拟机下安装了ubuntu中要输入用户名,一般情况下大家都会输入一个自己的网名或绰号之类的,密码也在这时设置过了. 但是当安装成功之后,使用命 ...
- Apache 强制SSL访问
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R ...
- MyEclipse img显示问题
MyEclipse第一个例子,通过HTML的img显示图片,费两天的功夫,故作简单整理,图片2不显示根本原因还是src的路径不对. 选中project中的sr.jpg文件,运行查看浏览器显示的地址,此 ...
- C#基础篇之C#和 .Net框架的概念和运行原理
一.微软平台的发展史 二..Net框架包含的东西 1.名词解释 BCL:基类库(Base Class Library)系统和底层提供的最基本的类库 CLR:公共语言运行时(Common Languag ...
- IntelliJ IDEA 2019.3 这回真的要飞起来了,新特性抢先看!
IntelliJ IDEA 才公布下一个主要版本 2019.3 的 Roadmap,近日就发布了 IntelliJ IDEA 2019.3 的首个早期访问版本(即 EAP 版本),版本号为 2019. ...