pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Read count ?
3+ messages / 2 participants
[nested] [flat]

* Read count ?
@ 2005-02-24 15:17 Aarni Ruuhimäki <aarni@kymi.com>
  2005-02-26 13:24 ` Re: Read count ? Ragnar Hafstað <gnari@simnet.is>
  0 siblings, 1 reply; 3+ messages in thread

From: Aarni Ruuhimäki @ 2005-02-24 15:17 UTC (permalink / raw)
  To: pgsql-sql

Hi,

Could someone please give a hint on how to query the following neatly ?

Get news from a news table that belong to a particular account, get segment 
name from segments table for each news item and read count from read history 
table that gets a news_id and timestamp insert every time the news is read. 
Display everything by news count, most read news first ?

news_id 4, news_header, segment_name x, read 10 times
news_id 2, news_header, segment_name y, read 8 times
news_id 1, news_header, segment_name x, read 7 times
news_id 3, news_header, segment_name x, read 0 times

news_table:
news_id, account_id, segment_id, news_header, ...

segments_table:
segment_id, account_id, segment_name

read_history_table:
history_id, news_id, timestamp


TIA,

Aarni
--------------
This is a bugfree broadcast to you
from **Kmail**
on **Fedora Core 2** linux system
--------------



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Read count ?
  2005-02-24 15:17 Read count ? Aarni Ruuhimäki <aarni@kymi.com>
@ 2005-02-26 13:24 ` Ragnar Hafstað <gnari@simnet.is>
  2005-02-28 13:08   ` Re: Read count ? Aarni Ruuhimäki <aarni@kymi.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Ragnar Hafstað @ 2005-02-26 13:24 UTC (permalink / raw)
  To: aarni@kymi.com; +Cc: pgsql-sql

On Thu, 2005-02-24 at 17:17 +0200, Aarni Ruuhimäki wrote:
> Hi,
> 
> Could someone please give a hint on how to query the following neatly ?
> 
> Get news from a news table that belong to a particular account, get segment 
> name from segments table for each news item and read count from read history 
> table that gets a news_id and timestamp insert every time the news is read. 
> Display everything by news count, most read news first ?
> 
> news_id 4, news_header, segment_name x, read 10 times
> news_id 2, news_header, segment_name y, read 8 times
> news_id 1, news_header, segment_name x, read 7 times
> news_id 3, news_header, segment_name x, read 0 times
> 
> news_table:
> news_id, account_id, segment_id, news_header, ...
> 
> segments_table:
> segment_id, account_id, segment_name
> 
> read_history_table:
> history_id, news_id, timestamp
> 

how about:

select news_id,news_header,segment_name,count(*) 
from news_table 
     natural join segments_table 
     natural join read_history_table
where account_id=? 
group by news_id,news_header,segment_name;

?

gnari





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Read count ?
  2005-02-24 15:17 Read count ? Aarni Ruuhimäki <aarni@kymi.com>
  2005-02-26 13:24 ` Re: Read count ? Ragnar Hafstað <gnari@simnet.is>
@ 2005-02-28 13:08   ` Aarni Ruuhimäki <aarni@kymi.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Aarni Ruuhimäki @ 2005-02-28 13:08 UTC (permalink / raw)
  To: Ragnar Hafstað <gnari@simnet.is>; +Cc: pgsql-sql

Hi,

Thanks Ragnar. This, and an other GROUP BY + name query within output got me 
there.

<cfquery name="get_news" datasource="#ds#"> 
SELECT DISTINCT news_id, news_header, segment, segment_id, count(*) 
FROM news_table 
NATURAL JOIN segments_table
NATURAL JOIN read_history 
WHERE account_id = #Url.account_id# 
GROUP BY news_id, news_header, segment, segment_id ORDER BY count DESC 
</cfquery>
...
<cfoutput query="get_news" group="news_id"> 
   
<cfquery name="get_seg" datasource="#ds#"> 
SELECT segment_name
FROM segments_table 
WHERE segment_id = #segment# 
    
</cfquery>

#news_header# - #get_seg.segment_name# - #count#

</cfoutput>


On Saturday 26 February 2005 15:24, you wrote:
> On Thu, 2005-02-24 at 17:17 +0200, Aarni Ruuhimäki wrote:
> > Hi,
> >
> > Could someone please give a hint on how to query the following neatly ?
> >
> > Get news from a news table that belong to a particular account, get
> > segment name from segments table for each news item and read count from
> > read history table that gets a news_id and timestamp insert every time
> > the news is read. Display everything by news count, most read news first
> > ?
> >
> > news_id 4, news_header, segment_name x, read 10 times
> > news_id 2, news_header, segment_name y, read 8 times
> > news_id 1, news_header, segment_name x, read 7 times
> > news_id 3, news_header, segment_name x, read 0 times
> >
> > news_table:
> > news_id, account_id, segment, news_header, ...
> >
> > segments_table:
> > segment_id, account_id, segment_name
> >
> > read_history_table:
> > history_id, news_id, timestamp
>
> how about:
>
> select news_id,news_header,segment_name,count(*)
> from news_table
>      natural join segments_table
>      natural join read_history_table
> where account_id=?
> group by news_id,news_header,segment_name;
>
> ?
>
> gnari
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings


--------------
This is a bugfree broadcast to you
from **Kmail**
on **Fedora Core 2** linux system
--------------
Linux is like a wigwam - no windows, no gates and an apache inside.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-02-28 13:08 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-24 15:17 Read count ? Aarni Ruuhimäki <aarni@kymi.com>
2005-02-26 13:24 ` Ragnar Hafstað <gnari@simnet.is>
2005-02-28 13:08   ` Aarni Ruuhimäki <aarni@kymi.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox