I have table having few number of columns wherein one column is for Execution number (exe_number) which stores the data in varchar(100).
select*from exedetails;
+------------+------------+------------+-------------+
| exe_number | pass_count | fail_count | error_count |
+------------+------------+------------+-------------+
| 02Aug_E1 | 98 | 9 | 0 |
| 31Jul_E1 | 94 | 8 | 1 |
| 30Jul_E2 | 76 | 9 | 3 |
| 01Aug_E2 | 98 | 7 | 0 |
| 02Aug_E2 | 76 | 8 | 2 |
| 30Jul_E1 | 98 | 12 | 9 |
| 31Jul_E2 | 91 | 6 | 1 |
| 01Aug_E1 | 67 | 14 | 2 |
+------------+------------+------------+-------------+
8 rows in set (0.00 sec)
describe exedetails;
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| exe_number | varchar(100) | YES | | NULL | |
| pass_count | int | YES | | NULL | |
| fail_count | int | YES | | NULL | |
| error_count | int | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
Here 30/31/01/02 are a date, Aug/Jul is a month and E1/E2 is Execution iteration (This is for my simplicity).
Lets consider present date is
'02 August 2022'
So I want to write a query in such a way that all records starting with
02Aug_
should be at the top of table. Means It should get arranged according to date so that present day record should be at the top.
Query I wrote for this is not giving desired result:
select exe_number from exedetails order by exe_number desc;
+------------+
| exe_number |
+------------+
| 31Jul_E2 |
| 31Jul_E1 |
| 30Jul_E2 |
| 30Jul_E1 |
| 02Aug_E2 |
| 02Aug_E1 |
| 01Aug_E2 |
| 01Aug_E1 |
+------------+
8 rows in set (0.00 sec)
select exe_number from exedetails order by exe_number asc;
+------------+
| exe_number |
+------------+
| 01Aug_E1 |
| 01Aug_E2 |
| 02Aug_E1 |
| 02Aug_E2 |
| 30Jul_E1 |
| 30Jul_E2 |
| 31Jul_E1 |
| 31Jul_E2 |
+------------+
8 rows in set (0.00 sec)
Expected Result :
+------------+
| exe_number |
+------------+
| 02Aug_E1 |
| 02Aug_E2 |
| 01Aug_E1 |
| 01Aug_E2 |
| 31Jul_E1 |
| 31Jul_E2 |
| 30Jul_E1 |
| 30Jul_E2 |
+------------+
Is there any way in MySQL/PostgreSQL by which I can get my desired solution?