I have this SQL Query which should find the rank of a certain cook.
I should compute the number of recipes this cook has made, compute the number of
other cooks recipes, and the final goal is to get our cook ranking,
which is the number of cooks who did less recipes then he did.
(Sorry for my bad English and the long explanation).
The query:
/*Compute Cooking Rank*/
create or replace function
ComputeCookingRank(u integer)
returns integer as $$
declare
uidSum record;
uSum integer;
ranking integer;
begin
select distinct uid,count(uid) as "sum" into uidSum from HasCooked group by uid;
---> select distinct into uSum from uidSum where uid=u;
select count(uid) into ranking from uidSum where uid=u and sum<uSum;
end;
$$ language plpgsql;
The problematic line is the one with the arrow; is it ok to take data from a ‘record’ type
variable like this?
What am I doing wrong here?
1 Answer