Query Related to Check Individual Values of Range!!!

From: "Jay Kumar Yadav" <jaykumaryadav1980(at)rediffmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Query Related to Check Individual Values of Range!!!
Date: 2006-05-26 14:05:08
Message-ID: 20060526140508.8154.qmail@webmail64.rediffmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Dear Friends/Sirs/Madams;

I would like to know about the query or function that can check each value between a range. By Use of Between if either value match, row is retrieved, i want to know is it possible to check all values of Between must be for particular field.

Any Idea/Suggetion/Comment would be appriciated and welcome.

Let me clear the Scenario;

In short;
Using Required Field table is as follows;

Table 'DIMENSIONS'

CREATE TABLE DIMENSIONS (
SNO SERIAL PRIMARY KEY,
ID NUMERIC,
YEAR NUMERIC);

INSERT INTO DIMENSIONS (ID, YEAR) VALUES (1,2005);
INSERT INTO DIMENSIONS (ID, YEAR) VALUES (1,2006);
INSERT INTO DIMENSIONS (ID, YEAR) VALUES (1,2007);

INSERT INTO DIMENSIONS (ID, YEAR) VALUES (2,2004);
INSERT INTO DIMENSIONS (ID, YEAR) VALUES (2,2005);
INSERT INTO DIMENSIONS (ID, YEAR) VALUES (2,2006);

INSERT INTO DIMENSIONS (ID, YEAR) VALUES (3,2005);
INSERT INTO DIMENSIONS (ID, YEAR) VALUES (3,2006);
INSERT INTO DIMENSIONS (ID, YEAR) VALUES (3,2007);

SELECT * from DIMENSIONS;
As follows :

SNO | ID | YEAR
----------------
1 | 1 | 2005
2 | 1 | 2006
3 | 1 | 2007
4 | 2 | 2004
5 | 2 | 2005
6 | 2 | 2006
6 | 3 | 2005
7 | 3 | 2006
8 | 3 | 2007
-----------------

I require the Query to Retrieve the 'ID' which Possess year between 2004 and 2006!
So for ID must have each year 2004, 2005, 2006.

If i use query with or without group on ID with Having or Where 'BETWEEN year 2004 and 2006' then ID 1,2 and 3 are listed but what i need is ID must have records for all 2004, 2005 and 2006 so Only ID=2 should retrieve.

SELECT ID FROM DIMENSIONS GROUP BY ID,YEAR HAVING YEAR BETWEEN 2004 and 2006;

It returns all 1,2,3 IDs.
I need ID having all values of 2004-2006 ( 2004,2005,2006) should be return means ID=2 here.

So for Front End can be used but i am trying to Utilize the DB if possible.

Thanks in Advance!!

Best Regard and Wishes.
- Jay kumar yadav.
9893123415.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oscar Ortiz 2006-05-26 14:28:24 Migrar una base de datos access a postgres
Previous Message Dave Cramer 2006-05-25 02:11:48 Re: postgresql 8.1.4