sql - Mysql stored function giving different results than original query (some conditions are not working) -


i have weird problem in mysql stored function. function returning different result if run query alone. here function:

delimiter $$ create definer=`admin`@`%` function `getaretention` (appid int(10), currentdate date)  returns int(11)     reads sql data     deterministic begin    return  (select count(distinct userid)                           session          (date(started) = currentdate  , appid=appid)); end 

here how call it:

select getaretention(5,date('2013-04-03')); 

here alone query:

select count(distinct userid)                           session          (date(started) = date('2013-04-03')  , appid=5) 

the function returning 2502 wrong. alone query returning 5, correct. also, if delete "and appid=5" alone query return 2502, means in stored function condition not working.

anyone have idea why? haven't used mysql while, missing something.

mysql cannot distinguish between variable name , column name here.

name variable otherwise:

delimiter $$ create definer=`admin`@`%` function `getaretention`         (         _appid int(10),         _currentdate date         )  returns int(11) reads sql data deterministic begin         return  (                 select count(distinct userid)                   session                   appid = _appid                        , started >= _currentdate                        , started < _currentdate + interval 1 day                 ); end $$ 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -