[AccessD] Top values query problem

Gustav Brock Gustav at cactus.dk
Wed May 10 04:00:34 CDT 2006


Hi Chester

Something like this where you use a pseudo key if you don't have a unique key:

  SELECT 
    PT_Well, 
    PT_Date, 
    PT_Status
  FROM 
    dbo_Prod_Tests
  WHERE
    Str(PT_Well) & "x" & Str(PT_Date) & "x" & Str(PT_Status) IN
      (SELECT TOP 6 
        Str(T.PT_Well) & "x" & Str(T.PT_Date) & "x" & Str(T.PT_Status)
      FROM 
        dbo_Prod_Tests As T
      WHERE
        dbo_Prod_Tests.PT_Well = T.PT_Well
      ORDER BY 
        T.PT_Well, 
        T.PT_Date DESC;)
  ORDER BY 
    PT_Well, 
    PT_Date DESC;

This assumes you have only one record for each Well/Date.

/gustav

>>> Chester_Kaup at kindermorgan.com 09-05-2006 23:34 >>>
When I run the following query I get the top 6 values for only the first
PT_Well which makes sense the way the query grid makes the query. How do
I change the query to get the top 6 for each PT_Well? Thanks.

SELECT TOP 6 PT_Well, PT_Date, PT_Status

FROM dbo_Prod_Tests

GROUP BY PT_Well, PT_Date, PT_Status

ORDER BY PT_Well, PT_Date DESC;





More information about the AccessD mailing list