سؤال

I have a query that returns a list of ID's and dollar amounts.

I want to sort my report that is based on this query by descending dollar amount but I want to put the ID's together. ie,

ID   Amount
--  --------
5    $90
3    $88
3    $5
9    $80

etc. Is there a way to do this using a Sort by 'expression'?

Thanks!

هل كانت مفيدة؟

المحلول

You are actually sorting by the maximum amount per ID, so you need access to that column in your report query:

SELECT a.id, 
       a.amount, 
       (SELECT Max(amount) 
        FROM   test b 
        WHERE  b.id = a.id) AS maxamount 
FROM   test a 
ORDER  BY maxamount DESC, 
          a.amount DESC; 

ID  AMOUNT  MAXAMOUNT
5   90      90
3   88      88
3   5       88
9   80      80

Once you have MAXAMOUNT in your query you can use it as the report sort criteria.

نصائح أخرى

See below:

select ID, Amount, ID & ' ' & Amount as ID_Amount_Together From Table ORDER BY Amount Desc;

Or if you do not want to concatenate Amount and ID then

select ID, Amount From Table ORDER BY Amount Desc;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top