SQL how to make null values come last when sorting ascending
问题 I have a SQL table with a datetime field. The field in question can be null. I have a query and I want the results sorted ascendingly by the datetime field, however I want rows where the datetime field is null at the end of the list, not at the beginning. Is there a simple way to accomplish that? 回答1: select MyDate from MyTable order by case when MyDate is null then 1 else 0 end, MyDate 回答2: (A "bit" late, but this hasn't been mentioned at all) You didn't specify your DBMS. In standard SQL