我有这个查询,返回给我的学生分数至少小于3分
SELECT s.name
FROM result r
JOIN student s ON r.student_id = s.student_id
GROUP BY s.name
HAVING COUNT(mark <= 3) > 2;
我有这个结果:
1 "John1"
2 "John10"
3 "John100"
4 "John1000"
5 "John10000"
6 "John100000"
7 "John10001"
8 "John10002"
9 "John10003"
10 "John10004"
但是当我基于这些查询创建一个函数时,它看起来像这样:
CREATE OR REPLACE FUNCTION public.red_zone()
RETURNS character varying
LANGUAGE 'sql'
VOLATILE
PARALLEL UNSAFE
COST 100
AS $BODY$
SELECT s.name
FROM result r
JOIN student s ON r.student_id = s.student_id
GROUP BY s.name
HAVING COUNT(mark <= 3) > 2;
$BODY$;
SELECT red_zone();
我有这个结果:
1 "John1"
为什么会这样?如何解决?
答案 0 :(得分:2)
您已定义函数RETURNS character varying
为单个值。您需要的是RETURNS SETOF character varying
,然后将其视为表或其他行源。
SELECT * FROM red_zone();
答案 1 :(得分:0)
RETURNS字符变化是错误