List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 22 2001 7:57pm
Subject:Re: Referer Count
View as plain text  
At 2:31 PM -0800 3/22/01, Daren Cotter wrote:
>I have a table, which keeps track of member information (including which
>member referred the member). To get a count of the # of referrals for member
>25, my query is:
>
>SELECT COUNT(*) FROM members WHERE ref1 = 25;
>
>To get a list of the top referers and the # of referrals they have, my query
>is:
>
>SELECT DISTINCT(ref1) AS member_id, COUNT(*) AS count FROM members GROUP BY
>ref1 ORDER BY count DESC LIMIT 100
>
>However, what I need, is a list of the top referers, along with their member
>information...name, email, password, etc. I tried using the following query,
>as I read about it in the MySQL manual, but it doesn't work:

You're asking for a summary as well as a listing.  You'll need two queries.
One to get the member_id for the top 25 referers, another to pull the
information for those members.  You can use ...WHERE member_id IN (list)
on the second query, where "list" is a comma separated list of the member_id
values.  Probably best to put this stuff in a Perl script or something so
that you can manipulate the list and construct the queries easily.

>
>SELECT DISTINCT(a.ref1) AS member_id, count(*) AS count, b.password,
>concat(UCASE(SUBSTRING(b.first_name,1,1)),
>LCASE(SUBSTRING(b.first_name,2,LENGTH(b.first_name)))) AS name, b.email,
>b.html_mail, b.ref1, DATE_FORMAT(b.signup_date, '%b %e, %Y') AS signup_date
>FROM members AS a, members AS b WHERE a.active_member = 'Y' AND a.ref1 =
>b.member_id GROUP BY a.ref1 ORDER BY count DESC LIMIT 10
>
>This gives me correct info for the distinct a.ref1 and count fields, and
>produces data for the rest of the fields, but it is not actually that
>member's data. Is this possible to do with one query? If I want to get the
>top 100 referers' data, I don't want to do 100 separate queries. Please
>help!


-- 
Paul DuBois, paul@stripped
Thread
Referer CountDaren Cotter22 Apr
  • RE: Referer CountBraxton Robbason22 Apr
  • Re: Referer CountPaul DuBois22 Apr
    • RE: Referer CountDaren Cotter22 Apr
  • Re: Referer CountKris Gonzalez23 Apr