This is a discussion on using the result of conditional statements in where within the MySQL Database forums, part of the Database Forums category; Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser, (@ageraw:=YEAR(CURRENT_DATE()) - YEAR(dateofbirth) - (RIGHT(CURRENT_DATE(),5)<'12-31')) AS temp, @age:=if( @ageraw > 100,0, if( @ageraw < 10,0 , @ageraw )) as age from users u --------- this works as a charm. But now I want to select users of a certain age, and I add a where clause: from users u having @age<50 This is not working. Nor is any other variant I can think of. How can this be achieved? greeting, and many thanks, Paul |
|
|||
|
> @age:=if( @ageraw > 100,0,
> if( @ageraw < 10,0 , > @ageraw > )) as age > > this works as a charm. But now I want to select users of a certain > age, and I add a where clause: > from users u having @age<50 As the fields is named "age", HAVING age<50 is what I would type. With the @ character, you call the contents of the variable, not the contents of a record field. Best regards -- Willem Bogaerts Application smith Kratz B.V. http://www.kratz.nl/ |
|
|||
|
Hi Willem
> As the fields is named "age", HAVING age<50 is what I would type. With > the @ character, you call the contents of the variable, not the contents > of a record field. Thanks for your reply. However, that does not work :-(( I get a syntaxerror.... any more idea's? Paul |
|
|||
|
On 31 jan, 09:53, "profke" <pwieg...@gmail.com> wrote:
> Hi Willem > > > As the fields is named "age", HAVING age<50 is what I would type. With > > the @ character, you call the contents of the variable, not the contents > > of a record field. > > Thanks for your reply. However, that does not work :-(( > I get a syntaxerror.... Well, not a syntax error.. i get a unknown field error... |