首页 > 试题广场 >

找出所有员工当前薪水salary情况

[编程题]找出所有员工当前薪水salary情况
  • 热度指数:367449 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
有一个薪水表,salaries简况如下:
emp_no 
salary
from_date 
to_date
10001
72527 2002-06-22
9999-01-01
10002
72527 2001-08-02
9999-01-01
10003
43311 2001-12-01 9999-01-01

请你找出所有员工具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示,以上例子输出如下:
salary
72527
43311

示例1

输入

drop table if exists  `salaries` ; 
CREATE TABLE `salaries` (
`emp_no` int(11) NOT NULL,
`salary` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`from_date`));
INSERT INTO salaries VALUES(10001,72527,'2002-06-22','9999-01-01');
INSERT INTO salaries VALUES(10002,72527,'2001-08-02','9999-01-01');
INSERT INTO salaries VALUES(10003,43311,'2001-12-01','9999-01-01');

输出

72527
43311
头像 N刻后告诉你
发表于 2020-05-19 20:30:02
题目:找出所有员工当前(to_date=‘9999-01-01’)具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示 方法1:distinct+order byselect distinct salaryfrom salarieswhere to_date='9999-01-01' 展开全文
头像 Num57.
发表于 2021-02-07 10:21:46
第一种 select DISTINCT(`salary`) from `salaries` order by `salary` desc第二种 select `salary` from `salaries` group by `salary` order by `salary` desc
头像 牛客764444695号
发表于 2020-03-11 16:06:17
select distinct(salary) from salaries where to_date='9999-01-01' order by salary desc; select distinct(salary) from salaries where to_date='9999-01 展开全文
头像 109号
发表于 2021-01-04 16:09:55
1.常规解法,使用DISTINCT和ORDER BY: SELECT DISTINCT salary FROM salaries WHERE to_date='9999-01-01' ORDER BY salary DESC 2.也可以使用GROUP BY :按照salary进行分组 SELECT 展开全文
头像 此用户名涉嫌违规
发表于 2021-03-02 15:48:18
题目要求找出所有员工具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示。 select distinct salary from salaries order by salary desc说到去重,脑子里第一反应就是distinct。看了一下大家的答案,有distinct和grou 展开全文
头像 高质量搬砖人
发表于 2021-01-29 10:50:39
方法)使用DISTINCT找出不重复的薪水 SELECT DISTINCT salary FROM salaries WHERE to_date = '9999-01-01' ORDER BY salary&nbs 展开全文
头像 jiang_dr
发表于 2021-09-29 10:18:06
思路:一个 group by 解决相同薪水只显示一次的问题,order by 解决逆序显示的问题 注意点:除了 group by 可以解决相同薪水显示一次的问题,也可以使用 distinct 来进行去重,其实两者没有什么差别,在重复量大的时候,group by 的效率比 distinct 稍高,在重 展开全文
头像 mlpan
发表于 2021-04-23 09:11:32
找出所有员工当前薪水salary情况 两种处理方法: 1、distinct 与 order by 的 结合使用 select distinct salary from salaries order by salary desc;2、group by 与 order by 的 结合 展开全文
头像 Java编程白哥
发表于 2023-03-09 09:38:53
方法一:思路:对工资去重,降序代码: select distinct salary from salaries where to_date='9999-01-01' order by salary desc 方法二:思路:用 group By 去重对工资去重,再降序。 group by 去重的性能高 展开全文
头像 冰山一角-牛客
发表于 2020-10-29 18:05:09
找出所有员工当前(to_date='9999-01-01')具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示CREATE TABLE salaries (emp_no int(11) NOT NULL,salary int(11) NOT NULL,from_date date 展开全文

问题信息

难度:
391条回答 29943浏览

热门推荐

通过挑战的用户

查看代码