4

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?

1 Answer 1

1

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; |
Sign up to request clarification or add additional context in comments.

2 Comments

You are awesome. It works!!! Thanks. But what i did wrong? Is it wrong to use 'SET' in a function?
@user3153534 You're most welcome... You have syntax error in your query. If you got desired output and an active member of stackoverflow try to accept and upvote the answer. How to use stackoverflow take a tour of that on this link stackoverflow.com/tour. It will describe how to accept and upvote the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.