Skip site navigation (1) Skip section navigation (2)

Help with sql statement grouping and distinct

From: David Inglis <david(dot)inglis(at)ideloveto(dot)com(dot)au>
To: pgsql-sql(at)postgresql(dot)org
Subject: Help with sql statement grouping and distinct
Date: 2004-07-07 04:38:42
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
I want to be able to select a distinct group of rows from 2 tables and then once
selected to group and total the results from the previous sql statement I have
been trying the following

select a.id_fk_accommodation, a.id_fk_selection,a.type,sum(1) from
acommodationlog a, log l
    where (id_fk_accommodation) in
           (select distinct a.id_fk_accommodation, a.id_fk_selection, a.type,
l.sessionid from accommodationlog a, log l where a.id_fk_log = l.id_pk and
id_fk_accommodation = 159 )
   group by a.id_fk_accommodation,a.id_fk_selection,a.type

I know this won't work due to incorrect number of columns in the in statement
but how do I achieve the above

Any help appreciated Thanks


David Inglis

This message was sent using IMP, the Internet Messaging Program.

pgsql-sql by date

Next:From: Dario V. FassiDate: 2004-07-07 06:31:25
Subject: ResultSerMetaData.getColumnDisplaySize() with timestamp error
Previous:From: Mike RylanderDate: 2004-07-07 03:28:30
Subject: Re: How to filter on timestamps?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group