mysql函数语法没有指定查询

时间:2014-01-02 12:11:50

标签: mysql sql function select where

功能如下:

delimiter |

create function average() returns int
    begin 
        declare AB int;
        set AB= avg(attribute1) from tablename where attribute2='AMG' ;
        return AB; 
    end; 
|

ERROR    No query specified

我做错了什么?

1 个答案:

答案 0 :(得分:1)

试试这个:

DELIMITER | 

    CREATE FUNCTION   average()
    RETURNS INT
    BEGIN DECLARE AB INT;
    SELECT AVG(attribute1) INTO AB FROM tablename WHERE attribute2='AMG' ;
    RETURN AB; END; |