How to assign variables in postgres sql [重复]

问题描述 投票:0回答:1
DECLARE 
eno integer := 0;
emp string ;

select into eno emp_no from "public"."salaries" GROUP BY emp_no ORDER BY max(salary) DESC LIMIT 1;
-- gives the emp_no of the employee with maximim salary

select INTO emp CONCAT(first_name, ' ' , last_name) as "Name" from "employees" 
WHERE emp_no = eno;
-- gives the name of the employee with the emp_no from preveous result 

raise NOTICE "The Employe with maximum salary is %",emp;

错误消息:错误:“整数”处或附近的语法错误

我试图获得最高薪水的 emp 名称 请帮忙

postgresql variables plpgsql valentina-studio
1个回答
0
投票

您需要将声明与值的初始化分开。

这样做:

DECLARE 
   eno integer;
BEGIN
   eno := 0;
... rest of your code here
END;
© www.soinside.com 2019 - 2024. All rights reserved.