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,
GBSomething like:
SELECT col1, MAX ( col2 )
FROM tbl
GROUP BY col1 ;
Anith|||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));
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.
Showing posts with label afeb. Show all posts
Showing posts with label afeb. Show all posts
Wednesday, March 7, 2012
Subscribe to:
Posts (Atom)