我有一个表名 candidateSalary
import numpy as np
A = []
A.append(values)
A1 = np.array(A)
B = []
B.append(values)
B1 = np.array(B)
np.savetxt(filename, zip(A1, B1), delimiter=',', fmt='%f')
我只想写一个查询来知道我的薪水等级。我正在尝试SQL的RANK()和DENSE_RANK()函数,但无法在mysql上运行。
我想要的输出是
+---------------+-----------+
| candidateID | Salary |
+---------------------------+
| 1 | 10000 |
| 2 | 12000 |
| 3 | 8000 |
| 4 | 5000 |
+---------------------------+
如果候选人排名不是1或2,则排名应该是所有其他候选人的3。
答案 0 :(得分:0)
这将返回dense_rank()
的等效内容:
select count(distinct cs.salary)
from candidateSalary cs
where cs.salary >= (select cs2.salary
from candidateSalary cs2
where cs2.candidateId = 2
);
或者如果您希望所有候选人都这么做:
select cs.*,
(select count(distinct cs.salary)
from candidateSalary cs2
where cs2.salary >= c2.salary
) as dense_rank
from candidateSalary cs;
答案 1 :(得分:0)
您可以如下使用:-
select candidateID,MAX(Salary) as sallary,rank from candidateSalary where candidateID = 2