Forum Moderators: open

Message Too Old, No Replies

Getting a handle on SELECT UNIQUE

Analysing log files ...

         

StupidScript

11:59 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a mySQL table containing a dump of Apache combined log files at 1.5M records.

As is normal with log files, each visitor has several entries. Since these logs comprise visits from PPC campaigns, each record includes:

id, ip_address, tracking_code

I'd like to run a query that gets a count of how many visitors came into the site by using any single PPC code.

Here are some example table entries:

0, 123.123.123.1, GOOGLE45
1, 123.123.123.1, GOOGLE45
2, 123.123.123.1, GOOGLE45
3, 12.12.12.2, GOOGLE45
4, 12.12.12.2, GOOGLE45
5, 234.234.234.45, YAHOO12
6, 145.145.145.145, YAHOO13
7, 145.145.145.145, YAHOO13

What I want to end up with is:

2 visitors came in with GOOGLE45 codes.
1 visitor came in with YAHOO12 code.
1 visitor came in with YAHOO13 code.

Would someone please get me on the right road, SELECT UNIQUE-wise ... or whatever the syntax will be? I'd really appreciate it. TIA.

aspdaddy

9:50 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, this should do it:

select tracking_code, count(tracking_code)
GROUP BY tracking_code

StupidScript

12:01 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great! Thanks!

I'm successfully using:

select tracking_code,count(tracking_code) from records group by ip_address

I really appreciate your help.

StupidScript

1:02 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The query works great from a shell. But ...

I have a new issue, and since it seems to be related to PHP query and result code, I have posted it here [webmasterworld.com].

If you have any illumination, I would be grateful for it.