Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 313 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Oracle order by descending with NULL last

#1
my objective is, to print the result of the query in "DESCENDING" order. but the problem is, the rows with NULL values went on top of the list.. how to put the null rows at the bottom, if the order by is descending?

select mysubcat.subcat
, mysubcat.subcatid as subcat_id
, (select SUM(myad.PAGEVIEW)
from myad
where MYAD.CREATEDDATE between '01-JUL-13 02.00.49.000000000 PM' and '13-JUL-13 02.00.49.000000000 PM'
AND MYAD.status = 1
and MYAD.mobileapp IS NULL
and myad.subcatid = mysubcat.subcatid )as web_views
from mysubcat
order by web_views desc;

the sample result goes like this

SUBCAT_ID WEB_VIEWS
Swimming Lessons 56 (null)
Medical Services 17 (null)
Mobile Phones & Tablets 39 6519
Home Furnishing & Renovation 109 4519


the order is in the descending order, I just want to put the rows with null values at the bottom of the printed result, so how?
Reply

#2
Use a `case`

order by case when web_views is not null
then 1
else 2
end asc,
web_views desc;
Reply

#3
You can use `DESC NULLS LAST` to achieve that.

Here is the [official documentation][1] from Oracle.

>**NULLS LAST**
>
>Specifies that NULL values should be returned after non-NULL values.

[1]:http://docs.oracle.com/javadb/10.8.1.2/ref/rrefsqlj13658.html

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through