| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 82067 | 2007-08-15 04:33:00 | MYSQL "CREATE FUNCTION" | somebody (208) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 581189 | 2007-08-15 04:33:00 | Does anyone have example of a MYSQL "CREATE FUNCTION statement? Here is my (non-working) attempt: CREATE FUNCTION avgTopN (uID INT(10), n INT(10)) RETURNS INT(10) RETURN SELECT avg(score) FROM (SELECT score FROM score_table WHERE userID=uID ORDER BY score DESC LIMIT n) AS tbl1; I'm trying to find one which includes a SELECT as a return statement. The only examples I can find do not include the execution of SELECTs. Also, don't tell me to search on Google as that's what I've been doing for the past hour. | somebody (208) | ||
| 581190 | 2007-08-15 08:31:00 | Sorry i can't actually help with the problem. I am currently studying for B.I.T and on Friday we have our Database tutorial so will ask the instructor and see what we come up with. (that is, if you can wait till Friday) :( |
Bozo (8540) | ||
| 581191 | 2007-08-15 09:31:00 | That would be great if you could. | somebody (208) | ||
| 581192 | 2007-08-16 04:33:00 | [bump] | somebody (208) | ||
| 581193 | 2007-08-16 05:55:00 | You're going to want to kill me. Class is canceled tomorrow :annoyed: So won't be able to get to ask tutor for help......yawn.... K, will take a look at it myself and see what happens. What error messages etc. do you get when you try and run it? |
Bozo (8540) | ||
| 581194 | 2007-08-16 07:29:00 | You're going to want to kill me. Class is canceled tomorrow :annoyed: So won't be able to get to ask tutor for help......yawn.... K, will take a look at it myself and see what happens. What error messages etc. do you get when you try and run it? No worries. The error I'm getting is "1064" Syntax error near "SELECT..." |
somebody (208) | ||
| 581195 | 2007-08-18 02:52:00 | Try removing the RETURN before the SELECT. I'm no expert on MySQL but a glace at the help page would seem to indicate this is not legal syntax. | TGoddard (7263) | ||
| 581196 | 2007-08-18 03:39:00 | Try removing the RETURN before the SELECT. I'm no expert on MySQL but a glace at the help page would seem to indicate this is not legal syntax. I'd tried that, but that also didn't work. I was following an example here: dev.mysql.com which uses the RETURN statement, without a SELECT (just concatenating two strings). In any case, I have found an alternative way of achieving what I wanted to achieve. Cheers for the help everyone. |
somebody (208) | ||
| 581197 | 2007-08-18 04:50:00 | Hey man, I can try to ask the question for you on Auckland U's software engineering forum. Which section would you like me to place the query under? https://forums.cs.auckland.ac.nz/ Cheers :) |
Renmoo (66) | ||
| 581198 | 2007-08-18 04:56:00 | Hey man, I can try to ask the question for you on Auckland U's software engineering forum. Which section would you like me to place the query under? https://forums.cs.auckland.ac.nz/ Cheers :) Don't worry about it - got it sorted now using a different technique (a slightly more complex query). |
somebody (208) | ||
| 1 | |||||