我有一个查询,我得到最大数量的“星星”
<cfquery datasource="Intranet" name="getMaxstars">
SELECT TOP (1) WITH TIES employee, SUM(execoffice_status) AS 'total_max'
FROM CSEReduxResponses
GROUP BY employee
ORDER BY 'total_max' DESC
</cfquery >
我还有一个不同的表EMPLOYEE。表EMPLOYEE也来自不同的datasource =“phonelist”。在此表中,我有员工first_name和last_name列,它们共享相同的列emp_id。 如何使用另一个表输出员工first_name和last_name。
我最终想要做的是输出: 最大: john doe - stars = 4
答案 0 :(得分:1)
使用如下的子查询:
select employee_id, sum(stars) as num_stars
from table_a
group by employee_id
having sum(stars) = (select max(num_stars)
from (select employee_id, sum(stars) as num_stars
from table_a
group by employee_id) x)
答案 1 :(得分:0)
SELECT TOP (1) WITH TIES employee_id, SUM(stars) AS 'total'
FROM Table_A
GROUP BY employee_id
ORDER BY 'total' DESC
这是另一种方法。