ORDER BY between two datetime columns

Asked

Viewed 14 times

1

I have two datetime columns: data1 and data2.

I need to sort by the shortest date between the two columns.

If data2 is not zero, displays data2 line;

If data2 is zero, displays data1 line;

inserir a descrição da imagem aqui

How do I do it? Please, thank you.

  • 1

    I solved it like this: SELECT data1, data2, REPLACE(data2,'0000-00-00 00:00:00', date(data1)) ordains FROM tabela ORDER BY orders ASC

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.