Google Answers Logo
View Question
 
Q: PHP: Sorting using aggregate functions ( No Answer,   0 Comments )
Question  
Subject: PHP: Sorting using aggregate functions
Category: Computers > Programming
Asked by: rossmcd-ga
List Price: $40.00
Posted: 28 Feb 2006 13:17 PST
Expires: 01 Mar 2006 07:24 PST
Question ID: 702024
I am building a topsites list, and in the process of ranking sites
have stumbled on a problem. I list sites in order of the sum of their
views in the last 7 days, from topsite_views which contains the number
of views for any given day there is more than 1 view. I know how to do
this.

My trouble is how to assign an actual rank number to the sites. I need
to find how many sites are above them and add 1 (I know this much),
but I don't know how to compare them when the actual calculation takes
place inside the query.

Here is an example: 

First, I find out the sum of views in last 7 days for the site in
question ($valuex), then I want to see how many sites are better:

$qry = "select sum(views) as viewsum from topsite_views where viewsum
>= '$valuex'";

Obviously, the query fails because it doesnt know what viewsum is
until the query is finished... yada yada..

HAve you any suggestions on how to do this? Many thanks in advance!

Clarification of Question by rossmcd-ga on 28 Feb 2006 13:27 PST
To clarify:

The query needs to count the number of sites in the toplist_views
table that have a sum of views column [where date <= curdate() and
date >= DATE_SUB(curdate(),INTERVAL 7 day)] which is greater than a
specific value. I cannot use subselects or subqueries because of my
mysql version.

For example, if I was just counting the sum of views for one site it would be:

$prerankqry = "select sum(views) as viewsum from toplist_views where
siteid='$siteid' and date <= curdate() and date >=
DATE_SUB(curdate(),INTERVAL 7 day) group by siteid";
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy