I am trying to find the housekeeper and the guide with the most tasks in their respective tables, and I am trying to do this with union to show in one result, but I'm getting this error:
"The TOP N WITH TIES clause is not allowed without a corresponding ORDER BY clause."
SELECT TOP 1 with ties e.EmpID as 'EmployeeID', Count(ScheduleID) as 'Task Count'
FROM EMPLOYEE e, CLEANING c
where e.empid = c.hkid
group by e.empid
UNION
SELECT TOP 1 with ties e.EmpID as 'EmployeeID', Count(ResID) as 'Task Count'
FROM EMPLOYEE e, RESERVATION r
where e.empid = r.guideid
group by e.empid
order by 'Task Count' desc
1条答案
按热度按时间w41d8nur1#
Try this one:
or this one: