sql - Using correctly HAVING with group by and COUNT -


i running query:

select u.id id,         count(distinct year(timestamp), week(timestamp)) cc,         group_concat(distinct year(timestamp),'-',week(timestamp))   users u         join checkins c           on c.userid = u.id  group  userid having count(cc) = 3 

and produces following results:

id  cc  05  3   2010-43,2010-47,2010-45  06  2   2010-44,2010-45  13  3   2010-43,2010-45,2010-48  20  3   2010-45,2010-43,2010-47  21  3   2010-43,2010-47,2010-45  22  2   2010-47,2010-48  25  3   2010-48,2010-43,2010-46  27  2   2010-42,2010-47  30  2   2010-48,2010-45  41  3   2010-44,2010-45,2010-47  44  2   2010-42,2010-44  50  2   2010-44,2010-47  52  2   2010-48,2010-47  57  2   2010-43,2010-44  71  3   2010-43,2010-48,2010-47  72  2   2010-43,2010-44  78  3   2010-47,2010-42,2010-43  79  2   2010-45,2010-46  80  2   2010-46,2010-44  87  1   2010-46  97  1   2010-48  108 3   2010-43,2010-47,2010-45  

as see cc column has values 2, 3, or 1.

how comes, when i've told having should 3?

mysql allow aliases in having clause. need use:

having cc = 3 

not

having count(cc) = 3 

in order filter results include rows have cc value of 3 though. i'm quite unsure though why having count(cc) = 3 return results @ all.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -