![]() |
something for brain training
Google visits my site and I log things:
data Code:
page1 date1for any page visit. so if date 1,5,7 would be 30.01.2001,10.01.2001,01.01.2001 respectively the result for page1 would be 15 (approx) how to do that, if possible at all ? |
It's possible, but it won't be an efficient query. I had to do something like this once upon a time.
Depending on how often you will do this and how much data there is to process, you might be best off doing it in a stored procedure and building a temporary table that holds the pairs. How much data is there? How often will you run the query? |
like 100.000 records now.
once or twice, just to see how google responds to my <changefreq> suggestions. |
Here is one way to do it.
You don't HAVE to create the views to make it work--you can do it with nested queries--but it's easier to see how it works by using the views. COMMENT: First, here is the data I am using. Like my table name? Code:
mysql> select * from bubikol;Code:
create view bview asCode:
create view bview2 as*************************************** COMMENT: This next dump is just so you can see how to get the number of days in each case. We don't actually use this query, per se, in the answer. Code:
select page, startdate, enddate, datediff(enddate,startdate) as daysdiffCOMMENT: And the final result: Code:
select page, AVG(DATEDIFF(enddate,startdate)) as averagedays |
If you care, here the whole thing is as a single query, no views:
Code:
SELECT page, AVG(DATEDIFF(enddate,startdate)) as averagedaysAnd I tried adding indexes on both fields in my "bubikol" table and found that only the index on page makes any difference at all (according to MySQL's EXPLAIN feature) and even then not that much. |
NOTE: Adding an index on page field helps a little, according to EXPLAIN. Adding one on the ondate field does nothing.
|
aha, I did not thought of min(enddate)
as Quote:
|
| All times are GMT +1. The time now is 05:10 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.