Results 1 to 2 of 2
  1. #1
    nggman is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    27

    Cannot have aggregate function in order by clause

    I have done some research on this but can't come up with a good solution. I have a crosstab query and I need to sort on an aggregated field. I need it to happen automatically (when the query runs) because I plan on making a macro.



    Here is my SQL. The field in bold is the one I need to sort by. Since I can not do the sort with this query as is, can I somehow place this SQL code inside of another query and somehow get it sorted?


    TRANSFORM Sum([dbo_RX Reporting].Price) AS SumOfPrice
    SELECT [dbo_RX Reporting].[Master Drug Name], Sum([dbo_RX Reporting].Price) AS Total
    FROM [dbo_RX Reporting]
    WHERE ((([dbo_RX Reporting].[Therapeutic Class]) Like "*Analg*") AND (([dbo_RX Reporting].Period) Like "2018*") AND (([dbo_RX Reporting].[Plan Name])="Alabama"))
    GROUP BY [dbo_RX Reporting].[Master Drug Name]
    PIVOT [dbo_RX Reporting].Period;

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make a query, Q1, that does the summing,
    then make a Crosstab of Q1

Please reply to this thread with any new information or opinions.

Similar Threads

  1. aggregate function help
    By ltcarlisle in forum SQL Server
    Replies: 16
    Last Post: 06-24-2014, 01:34 PM
  2. Cannot Have Aggregate function
    By vitordf in forum Queries
    Replies: 4
    Last Post: 08-13-2013, 07:24 AM
  3. Replies: 5
    Last Post: 11-07-2012, 08:15 AM
  4. Order By Clause Issue
    By josh in forum Queries
    Replies: 5
    Last Post: 02-22-2012, 04:35 PM
  5. more aggregate function questions
    By boutwater in forum Access
    Replies: 6
    Last Post: 09-29-2011, 02:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums