views:

28

answers:

2

I have this table

CREATE OR REPLACE TABLE hits (ip bigint, page VARCHAR(256), agent VARCHAR(1000), 
                              date datetime)

and I want to calculate googlebot visit frequency for every page.

... WHERE agent like '%Googlebot%' group by page
+3  A: 

Use:

  SELECT page,
         COUNT(*)
    FROM hits
   WHERE agent LIKE '%Googlebot%'
GROUP BY page
OMG Ponies
+1  A: 

Try this:

select page, count(1) as visits
  from hits
 where agent like '%Googlebot%'
 group by page;
Pablo Santa Cruz
why `count(1)` ?
stereofrog
@stereofrog: why not?
Pablo Santa Cruz
@Pablo, just wanted to know, is it the same as count(*) or somehow better?
stereofrog
@stereofrog: It's basically the same. You just care about counting rows, so count(1) is all you need. Check this out: http://stackoverflow.com/questions/2710621/count-vs-count1-vs-countpk-which-is-better
Pablo Santa Cruz
nice stuff, thanks
stereofrog