Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
newbie2006
Starting Member
7 Posts |
Posted - 2007-07-12 : 20:57:42
|
Hi there I am using MS Access and am trying to extract the region information from my vendorquery and find the earliest period and latest period for each. My data looks like (RID=regionID):RID Year Quarter1 1997 21 1997 32 1998 22 1999 1I need to retrieve the followingRID Year Quarter1 1997 22 1998 2This is to select the minimum year for that Region_idSELECT vendorquery.Region_ID, Min(vendorquery.Year) AS MinOfYearFROM vendorqueryGROUP BY vendorquery.Region_ID;and this is to select the min quarter for that YearSELECT vendorquery.Year, Min(vendorquery.Quarter) AS MinOfQuarterFROM vendorqueryGROUP BY vendorquery.Year;I tried to combine themSELECT vendorquery.Region_ID, Min(vendorquery.Year) AS MinOfYear, Quarter FROM vendorqueryInner join (SELECT vendorquery.Year, Min(vendorquery.Quarter) AS MinOfQuarterFROM vendorqueryGROUP BY vendorquery.Year) as B on B.Year=vendorquery.YearGROUP BY vendorquery.Region_IDbut it doesnt seem to work, the error message was that i did not use "quarter" as part of an aggregate function. If i did a group by region_id, quarter, then i will not be retrieving the resultset that i wanted. How should i combine the 2 SELECT?(moved to the Access forum) |
|
ashley.sql
Constraint Violating Yak Guru
299 Posts |
Posted - 2007-08-09 : 16:59:07
|
Its not clear what exactly you are trying to do.Will you not need the data for 1999 in the result set.Also post some more data along with scripts for tables. That way you will get more responses.Ashley Rhodes |
 |
|
|
|
|