0

I have data like this:

Customer ID Name Type Last Submit
1 Patricio C January 2022
2 Dale A June 2022
3 Yvonne C July 2022
4 Pawe C JUne 2022
5 Sergio B August 2022
6 Roland C August 2022
7 Georg D November 2022
8 Catherine D October 2022
9 Pascale E October 2022
10 Irene A November 2022

How to sort type A out of the queue first like A,B,C,D,E,F, then the last submit is at the top.

The example output:

Customer ID Name Type Last Submit
10 Irene A November 202[![enter image description here][1]][1]2
1 Dale A June 2022
5 Sergio B August 2022
6 Roland C August 2022
3 Yvonne C July 2022
4 Pawe C June 2022
1 Patricio C January 2022
7 Georg D November 2022
8 Catherine D October 2022
9 Pascale E October 2022
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • What data type is column `Last submit` - if this is actually a *date* it should not be a *string*. – Stu Nov 10 '22 at 12:11

4 Answers4

0

So basically you want to sort by 2 different columns, this is detailed in this other answer: SQL multiple column ordering

In your example you would do

ORDER BY type, last_submit
Stefan Stroe
  • 16
  • 1
  • 4
0

Hi you can use simple order by in postgresql like this

SELECT
     *
FROM
    table (your table name)
ORDER BY
    type ASC, last_submit DESC; 
0

In this case, you need to sort your query using the two columns in order.

Add this part to the end of your query.

ORDER BY type, last_submit DESC; 

Check out this question "SQL multiple column ordering"

0

This code should get you your desired output.

SELECT 
     customer_ID,
     Name,
     Type,
     Last_Submit
FROM 
     [schema name].[your table name]
ORDER BY 
     Type ASC, Last_Submit DESC
helvete
  • 2,455
  • 13
  • 33
  • 37
Aniket
  • 34
  • 6