delimiter //
drop function if exists get_rating;
create function get_rating(id tinyint(1) unsigned)
returns tinyint(1)
begin
declare rating int unsigned;
declare rating_count int unsigned;
select sum(rating), count(rating)
into rating, rating_count
from comments
where review_id = id;
return rating_count;
end //
delimiter ;
當我調用該函數時,rating和rating_count都不會返回正確的值(3),它們都返回0,當它應該添加三個值爲1的字段時。爲什麼這不起作用?MySQL選擇多個變量不起作用
你也有名字'id'列在表中'comments'? –
@Ravinder編號從函數聲明中可以看出,它是一個傳入的值。 – boompow