sql statement series (row and column processing) [chapter eight hundred first chapter]

Null processing time for sorting

For example:
the SELECT * from EMP by the Order COMM

I need to deal with desc red frame part, that is, in descending order.

Resolution:

Focusing on how to make null for independence.

select * from 

(select *,case when COMM is null then 0 else 1 end as COMMISNULL from EMP )
x
order by COMMISNULL,COMM desc

Solution: a singled out independently to null.

Note that judgment is null is not equal number

Based on conditional logic to dynamically adjust to sort items

For example:

select * from EMP

I hope that is: if the job is SALESMAN, then sorted according to COMM, SAL or sorting

solution:

In one example above, we ranking is that for a further processing by excluding certain row line.
And our case is for the column, if it is so much simpler for the column.

select *
from EMP
order by case when JOB='SALESMAN' then COMM else SAL end

Guess you like

Origin www.cnblogs.com/aoximin/p/12543642.html