Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping dates cause overlap

Status
Not open for further replies.

hkaing79

Technical User
Jul 26, 2004
234
0
0
US
I have a table with tblPrice having fields:
StartDate ProductID Price
1/1/06 1 $10
1/2/06 1 $10
1/3/06 1 $5
1/4/06 1 $10

Is it possible to query this table so the result would look like:

ProductID Price MinDate MaxDate
1 $10 1/1/06 1/2/06
1 $5 1/3/06 1/3/06
1 $10 1/4/06 1/4/06

Using Min and Max will give me only two lines:
1, $10, 1/1/06-1/4/06
1, $5, 1/3/06

Any ideas would be greatly appreciated.

Thanks.
 
maybe something like:

SELECT A.PRODUCTID, A.PRICE, A.STARTDATE AS MINDATE, B.STARTDATE AS MAXDATE
FROM TBLPRICE A
INNER JOIN TBLPRICE B ON A.PRODUCTID < B.PRODUCTID



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases:
The Fundamentals of Relational Database Design
Understanding SQL Joi
 
nope that's not right (joined on the wrong field!), try this:

SELECT A.PRODUCTID, A.PRICE, A.STARTDATE AS MINDATE, B.STARTDATE AS MAXDATE
FROM TBLPRICE A
INNER JOIN TBLPRICE B ON A.STARTDATE < B.STARTDAT

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases:
The Fundamentals of Relational Database Design
Understanding SQL Joi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top