如何在MySQL函数中对输出进行排名

时间:2018-10-19 09:18:10

标签: mysql

我使函数查询正常工作,但是我想对输出进行排名。多谢您的协助。该代码正在计算员工服务的客户数量

create or replace function count_service
 (employee_no1 in varchar2)
  return number is
cursor a is select  count(customer_no) tot
    from ORDERS
    where employee_no=employee_no1;
a_var a%rowtype;
begin
 open a;
 fetch a into a_var;
 if a%notfound then
     return 'No such employee';
 else
     return a_var.tot;
 end if;
 end;
 /

declare
total number;
begin
for a in (select employee_no from employee)
loop 
total := count_service(a.employee_no);
dbms_output.put_line('employee no'||' '||a.employee_no ||' '||'people 
served'||' '|| total);
end loop;
end;

OUTPUT
employee no 1000 people served 10
employee no 1001 people served 14
employee no 1002 people served 13
employee no 1003 people served 0

0 个答案:

没有答案