資料庫SQL實戰 --15.獲取當前薪水第二多的員工的emp_no以及其對應的薪水salary
題目描述
獲取當前(to_date='9999-01-01')薪水第二多的員工的emp_no以及其對應的薪水salary
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`));
解決思路
select emp_no, salary from salaries where to_date = '9999-01-01' and salary = (select distinct salary from salaries order by salary desc limit 1,1)
- 注意用distinct去重,不然查詢處理結果可能有多個
相關推薦
資料庫SQL實戰 --15.獲取當前薪水第二多的員工的emp_no以及其對應的薪水salary
題目描述 獲取當前(to_date='9999-01-01')薪水第二多的員工的emp_no以及其對應的薪水salary CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL, `salary` int(11) NOT NULL, `fr
資料庫SQL實戰 —— 獲取當前(to_date='9999-01-01')薪水第二多的員工的emp_no以及其對應的薪水salary
時間限制:1秒 空間限制:32768K 題目描述 獲取當前(to_date='9999-01-01')薪水第二多的員工的emp_no以及其對應的薪水salary CREATE TABLE `sala
資料庫SQL實踐18:獲取當前薪水第二多的員工的emp_no以及其對應的薪水salary,不準使用order by
思想: 題目要求查詢當前薪水(to_date='9999-01-01')排名第二多的員工編號emp_no、薪水salary、last_name以及first_name,不準使用order by。首先通過條件e.emp_no=s.emp_no將兩表內連線相連,然後通過條件to_date='9999
資料庫SQL實踐17:獲取當前薪水第二多的員工的emp_no以及其對應的薪水salary
思想: 題目要求獲取當前(to_date='9999-01-01')薪水第二多的員工的emp_no以及其對應的薪水salary。首先通過條件to_date = '9999-01-01'獲取當前薪水,其次通過條件order by salary desc limit 1,1找到薪水第二多的員工(前提
資料庫SQL實戰 --10.獲取所有部門中當前員工薪水最高的相關資訊
題目描述 獲取所有部門中當前員工薪水最高的相關資訊,給出dept_no, emp_no以及其對應的salary CREATE TABLE `dept_emp` ( `emp_no` int(11) NOT NULL, `dept_no` char(4) NOT
資料庫SQL實戰 —— 統計出當前各個title型別對應的員工當前薪水對應的平均工資。結果給出title以及平均工資avg。
時間限制:1秒 空間限制:32768K 題目描述 統計出當前各個title型別對應的員工當前薪水對應的平均工資。結果給出title以及平均工資avg。 CREATE TABLE `salaries
牛客網資料庫之獲取當前薪水第二多的員工的emp_no以及其對應的薪水salary
題目: 思路一: 在小於最高salary的資料集中找最高salary SELECT emp_no,MAX(salary) FROM salaries WHERE to_date = '9999-01-01' AND salary <( SELECT MAX
《資料庫SQL實戰》獲取所有員工當前的manager
題目:獲取所有員工當前的manager,如果當前的manager是自己的話結果不顯示,當前表示to_date=’9999-01-01’。 結果第一列給出當前員工的emp_no,第二列給出其manage
【資料庫SQL實戰】查詢薪水漲幅超過15次的員工號emp_no以及其對應的漲幅次數t
題目描述 查詢薪水漲幅超過15次的員工號emp_no以及其對應的漲幅次數t CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL, `salary
資料庫SQL實踐7:查詢薪水漲幅超過15次的員工號emp_no以及其對應的漲幅次數t
思想: 題目要求查詢薪水漲幅超過15次的員工號emp_no以及其對應的漲幅次數t。首先通過group by函式對emp_no進行分組,將同一個emp_no的記錄分為一組並通過count(*)計算這個emp_no組中一共有幾條記錄,最後通過having函式找出記錄數大於15的。 知識點:
資料庫SQL實戰15:查詢employees表
思想: 題目要求查詢employees表所有emp_no為奇數,且last_name不為Mary的員工資訊,並按照hire_date逆序排列。首先通過條件(emp_no%2)=1找出所有奇數的emp_no,其次通過條件last_name!='Mary'找出last_name不為Mary的員工,最
資料庫SQL實戰12:獲取所有部門中當前員工薪水最高的相關資訊
思想: 題目要求獲取所有部門中當前員工薪水最高的相關資訊,給出dept_no, emp_no以及其對應的salary。首先通過條件d.to_date = '9999-01-01'找出所有部門當前員工,然後通過條件s.to_date = '9999-01-01'找出各員工當前
資料庫SQL實戰 --14.統計出當前各個title型別對應的員工當前薪水對應的平均工資
題目描述 統計出當前各個title型別對應的員工當前薪水對應的平均工資。結果給出title以及平均工資avg。 CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL, `salary` int(11) NOT NULL, `from_
資料庫SQL實戰3:查詢各個部門當前領導當前薪水詳情以及其對應部門編號dept_no
思想: 題目要求查詢各個部門當前領導當前薪水詳情以及其對應部門編號dept_no。首先根據當前領導通過條件d.to_date = '9999-01-01'進行篩選,然後當前薪水通過條件s.to_date = '9999-01-01'進行再次篩選,最後根據領導的編號通過條件d.emp_no = s
資料庫SQL實戰 --3.查詢各個部門當前領導當前薪水詳情以及其對應部門編號
題目描述 查詢各個部門當前(to_date=‘9999-01-01’)領導當前薪水詳情以及其對應部門編號dept_no CREATE TABLE `dept_manager` ( `dept_no` char(4) NOT NULL, `emp_no` int(
資料庫SQL實戰 —— 獲取所有員工當前的manager
時間限制:1秒 空間限制:32768K 題目描述 獲取所有員工當前的manager,如果當前的manager是自己的話結果不顯示,當前表示to_date='9999-01-01'。 結果第一列給出當
刷題-----【資料庫SQL實戰】查詢的員工號emp_n薪水漲幅超過15次o以及其對應的漲幅次數t(親測正確的)
題目描述 查詢薪水漲幅超過15次的員工號emp_no以及其對應的漲幅次數t CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL, `salary` int(11) NOT NULL, `from_date` date NO
《資料庫SQL實戰》統計出當前各個title型別對應的員工當前薪水對應的平均工資。
題目描述 統計出當前各個title型別對應的員工當前薪水對應的平均工資。結果給出title以及平均工資avg。 CREATE TABLE salaries ( emp_no int(11) NOT
資料庫SQL實戰 --12.從titles表獲取按照title進行分組,注意對於重複的emp_no進行忽略
題目描述 從titles表獲取按照title進行分組,每組個數大於等於2,給出title以及對應的數目t。 注意對於重複的emp_no進行忽略。 CREATE TABLE IF NOT EXISTS "titles" ( `emp_no` int(11) NOT NULL, `tit
資料庫SQL實戰 --11.從titles表獲取按照title進行分組
題目描述 從titles表獲取按照title進行分組,每組個數大於等於2,給出title以及對應的數目t。 CREATE TABLE IF NOT EXISTS "titles" ( `emp_no` int(11) NOT NULL, `title` varchar(50) NOT