mysql - How to write SQL to check conditions? -


I have to write a SQL code that will do the following:

  1. If there is only one Return the record in which the situation is 'pending' and return.
  2. If there are multiple records with 'Pending' status, then the most recent 'created date'
  3. Li> if there are no 'pending' records and only 'active' records Choose one with the most recent 'created_date'
  4. 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

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -