DEV Community

Discussion on: What was your win this week?

Collapse
 
swlkr profile image
Sean Walker

I was trying to calculate unique pageviews for todayinclojure.com with a subquery

select
  count(ip_count) as visits,
  day
from (
  select
    count(ip) as ip_count,
    created_at - (created_at % 86400) as day
  from stat
  where
    created_at >= ?
  group by ip
  order by day desc
) as stat
group by day
order by day desc

but used distinct instead

select
  count(distinct ip) as visits,
  created_at - (created_at % 86400) as day
from stat
where
  created_at >= ?
group by day
order by day desc

and it worked.

No code? Try no scale.