mysql - How to write SQL to check conditions? -
I have to write a SQL code that will do the following:
- If there is only one Return the record in which the situation is 'pending' and return.
- If there are multiple records with 'Pending' status, then the most recent 'created date' Li> if there are no 'pending' records and only 'active' records Choose one with the most recent 'created_date'
- If there are some 'pending' and some 'approved' records, then priority should be given to the 'pending' record with the most recent date < / Li>
I tried the statements of statements, but it is not working well Please help.
Since you tagged it both ways:
Sql Server:
SELECT TOP 1 * from [MyTable] Where in the case of status ('pending', 'active') when the situation = ' Where Pending 'MyTable' is located ('Pending', 'Active') with case 1 = 1 MySQL: SELECT * when position = 'Pending 'Then, 0 or 1 E & amp; ndash;, created demat limit of BSD 1
Comments
Post a Comment