Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How would modify a query to group by a field and within each grouping, have an order by clause?

Posted on 2014-01-10
5
314 Views
Last Modified: 2014-01-10
I am working with a query using Access 2003.

How would you modify the following query to order the records by
 [Age(Days)] DESC within tblBanks.[Senior Management

In other words I want to group records by the field tblBanks.[Senior Management
and withinin each grouping, the records should be sorted in [Age(Days)] DESC.


SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E");
UNION ALL
SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("B","C")
ORDER BY [Age(Days)] DESC;
0
Comment
Question by:zimmer9
  • 3
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39772206
try this


select x.*
From
(SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E");
UNION ALL
SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("B","C")
) As X
Order By x.[Age(Days)] Desc


or use use this Order bY

Order By 11 DESC
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 39772531
ORDER BY [Senior Management Tab], [Age(Days)] DESC

OR

ORDER BY [Senior Management Tab] ASC, [Age(Days)] DESC
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39772565
oops sorry, forgot about the Management group


select x.*
From
(SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E");
UNION ALL
SELECT tblOpenItems.[Process Date], tblOpenItems.[Trans Date], tblBanks.[Bank Code] AS [BRS#],
tblBanks.[GLAcct#] As [Taps/Margin],
tblBanks.[ACCOUNT#] As [Bank Account Number],  tblOpenItems.T As [_Type], tblOpenItems.Type As [Trans Code],
tblOpenItems.Description,
tblOpenItems.[Office] & ' ' & [CheckNum] As [Check/Reference#],
tblOpenItems.Amount,  tblOpenItems.AgeDays As [Age(Days)], tblOpenItems.footnote As Comments,
tblBanks.[Report Name] As Responsibility,tblBanks.Currency,tblBanks.[Senior Management Tab]
FROM tblDates, tblBanks INNER JOIN tblOpenItems ON tblBanks.[Bank Code]=tblOpenItems.Bank
Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("B","C")
) As X
Order By X.[Senior Management Tab], x.[Age(Days)] Desc




.
0
 

Author Comment

by:zimmer9
ID: 39772593
Please see attached doc. Thank you.
Synax.doc
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39772633
remove the semi colon  from this line

Where tblBanks.[RISK REPORT] = 'YES' AND tblOpenItems.t In ("A","D","E"); '<<<<
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question