我有一张桌子fanclubs (f_count_m /*count of members*/, id_band /*id of the music band*/)
,我需要一个返回id_band
最受欢迎乐队的函数。
代码:
delimiter //
create function best_of (b varchar(2))
returns varchar(6)
begin
DECLARE b varchar(6);
SET @b =
(select s_and_id.id_band from
(select sum(f_count_m), id_band
from fanclubs
group by id_band
order by f_count_m desc
LIMIT 0,1) as s_and_id);
return b;
end//
delimiter ;
该select
部分返回一个id
。但是,如果我尝试使用这样的创建函数:
select @best_of
或者
select * from fanclubs where id_band = @best_of
我得到NULL。
与@b
我哪里错了?