sql - setting alias on mysql columns with math operators -
this sql query getting error @ statement.
select a.*, b.*, (a.date - b.date) before tbl a join tbl b b on a.id = b.id (a.date - b.date) < 5 , (a.date - b.date) > 0;
how can make sql query , working?
select a.*, b.*, (a.date - b.date) before tbl a join tbl b b on a.id = b.id before < 5 , before > 0;
before
reserved word. use else or use backticks:
select a.*, b.*, (a.date - b.date) datediff tbl a join tbl b b on a.id = b.id (a.date - b.date) < 5 , (a.date - b.date) > 0;
the list of reserved words here. before
used in definition of triggers (and perhaps other places).
edit:
for second question, can use having
clause if want:
select a.*, b.*, (a.date - b.date) datediff tbl a join tbl b b on a.id = b.id having datediff < 5 , datediff > 0;
this mysql extension having
. looks awkward not familiar (it screaming, "where group by
"). but, can useful, particularly longer, more complicated expressions.
Comments
Post a Comment