select - mysql using calculated column at where/having -
i have question how use "alias" column @ where/having clause. know there question related topic. search trough web , on stackoverfolw , doesn't find solution.
so hope @ way..
the following statement works well:
select phrase,count(*) my_statistics timestamp>now()-interval 7 day group phrase order desc limit 16;
phrase
, timestamp
are columns @ table. code selects top 16 phrases, inserts users on last 7 days. there exist column user , select top 16 phrases inserted more 1 user. tried this:
select phrase,count(*) a, count(distinct(user)) b my_statistics timestamp>now()-interval 7 day , b>1 group phrase order desc limit 16;
on other questions on stackoverflow fond info, have use having
select phrase,count(*) a, count(distinct(user)) b my_statistics timestamp>now()-interval 7 day group phrase order desc having b>1 limit 16;
but returns error:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'having b>1 limit 16' @ line 5
i have no idea, how right syntax be. hope kind of here. thank you!
place order desc
after having
clause.
select phrase, count(*) a, count(distinct( user )) b my_statistics timestamp > now() - interval 7 day group phrase having b > 1 order desc limit 16;
Comments
Post a Comment