我发现当我选择一个avg(列)到一个变量时,它是OK。但是当我选择一个以上的avg变量时,它是错误的。我不想写两次,如何修复它?
//work well
SELECT
avg(MathPoint) into MathPoint
from student
where sex=1
SELECT
avg(EnglishPoint) into EnglishPoint
from student
where sex=1
//do not work
SELECT
avg(EnglishPoint) into EnglishPoint,
avg(MathPoint) into MathPoint,
from student
where sex=1
答案 0 :(得分:1)
INTO
使用时出现语法错误。
INTO
应该跟随所有变量名称。
示例:
SELECT
avg(EnglishPoint), avg(MathPoint)
into EnglishPoint, MathPoint
from student
where sex=1
文档:
SELECT ... INTO var_list
选择列值并将其存储到
变量