Home All Groups Group Topic Archive Search About
Author
12 May 2005 6:34 PM
GB
Hello,
I have a table T1:

Date   |   Value
---------------------
Jan        A
Feb       A
Feb       B
Mar       A
Mar       B
Apr       A
May      A

I need a query to get dataset like this for ANY VALUE with maximum
daterange:

Date  | Value
--------------------
Jan      A
Feb     A
Mar     A
Apr      A
May     A

Thanks,
GB

Author
12 May 2005 9:33 PM
--CELKO--
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.   if you had follwoed basic netiquette, would you have
posted this?

CREATE TABLE Foobar
(month_name CHAR(3) NOT NULL,
foo_value CHAR(1) NOT NULL,
PRIMARY KEY (month_name, foo_value));

>> I need a query to get dataset like this for ANY VALUE with maximum
date range: <<

I am going to guess you mean a foo_value that appears in all the
months.

SELECT foo_value
  FROM Foobar AS F1
GROUP BY foo_value
HAVING COUNT(*)
          = (SELECT COUNT(DISTINCT month_name) FROM Foobar);

This depends my guess at the DDL you never posted.

AddThis Social Bookmark Button