user3153534
user3153534

Reputation: 53

mysql function syntax no query specified

the function is this:

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

What i do wrong?

Upvotes: 4

Views: 2784

Answers (1)

Saharsh Shah
Saharsh Shah

Reputation: 29051

Try this:

DELIMITER | 

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

Upvotes: 1

Related Questions