difficult query

From: Jakub Ouhrabka <jouh8664(at)ss1000(dot)ms(dot)mff(dot)cuni(dot)cz>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: difficult query
Date: 2002-05-04 14:00:11
Message-ID: Pine.LNX.4.33.0205041559440.17441-100000@u-pl2
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I'd like to ask how to write sql query returning following results without
using any other table than table1 (e.g. without outer join with table
containing all possible day numbers...)

table1:
day | data
------------
1 | x
1 | x
2 | x
4 | x
4 | x

I'd like to write query returning this:

query results:
day | number of records for a day
----------------------
1 | 2
2 | 1
3 | 0 <--- !!!
4 | 2

Is it possible to do this in sql?

thanks a lot, kuba

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ian Barwick 2002-05-04 15:44:48 Re: difficult query
Previous Message Tom Lane 2002-05-03 22:24:01 Re: Returning composite types from a plpgsql function