我有以下SQL代码:
select user_id, quest_registration.quest_id, count(quest.quest_id), quest.quest_rarity,
case quest.quest_rarity
when 1 then count(user_id) * 1
when 2 then count(user_id) * 2
when 3 then count(user_id) * 3
when 4 then count(user_id) * 4
when 5 then count(user_id) * 5
end as points,
SUM(points)
from quest_registration
inner join quest
on quest_registration.quest_id = quest.quest_id
where user_id=2 AND quest_registration.date_completed is not null
group by quest.quest_rarity;
我想显示点总和列。我该怎么做?
解决 新问题
我有以下创建功能:
CREATE FUNCTION points_earned (u_id INT)
RETURNS INT
BEGIN
DECLARE cnt1 INT DEFAULT 0;
select SUM(points)
from (select case quest.quest_rarity
when 1 then count(user_id) * 1
when 2 then count(user_id) * 2
when 3 then count(user_id) * 3
when 4 then count(user_id) * 4
when 5 then count(user_id) * 5
end as points
from quest_registration inner join quest
on quest_registration.quest_id=quest.quest_id
where user_id=2 AND quest_registration.date_completed is not null
group by quest.quest_rarity) x;
RETURN cnt1;
END $$
这个创建函数代码给出了一个错误:第3行的ERROR 1415(0A000):不允许从函数返回结果集
这是什么意思?