From: | Paulo Jan <admin(at)digital(dot)ddnet(dot)es> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Getting statistics from tables |
Date: | 2002-04-09 17:00:34 |
Message-ID: | 3CB31E32.18EBD4BB@digital.ddnet.es |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi all:
Let's say I have a table that keeps track of the pages that an user has
seen in my website, something like:
Users | Pages
-----------------------------
pepe | index.html
johnsen | about.html
paco | about.html
paco | index.html
pepe | download.html
It's easy to see the last 5, or 10, or 15 pages that an user has seen,
or the last users that have viewed a page. But how can I find out the 5
most seen pages, or the 5 most frequent users? My first thought (to find
the most viewed pages) was to:
1) "SELECT DISTINCT pages FROM <table>"
2) For each page, "SELECT count(users) FROM <table> WHERE
pages='<page>'"
3) Find out the 5 pages that have returned the highest counts.
At which point I imagined the perfomance problems that all the above
would cause in a dynamic page (PHP) and said to myself "ew!!".
Is there any other way? Any built-in function in Postgres that can do
this, perhaps?
(I used pageviews just as an example; what I have is a number of
similar situations where I need to find out this kind of data, and in
all of them said data is updated dynamically and needs to be displayed
in real time).
Paulo Jan.
DDnet.
From | Date | Subject | |
---|---|---|---|
Next Message | Fran Fabrizio | 2002-04-09 17:34:41 | Re: Getting statistics from tables |
Previous Message | Papp, Gyozo | 2002-04-09 16:23:00 | Re: SPI_execp() failed in RI_FKey_cascade_del() |