我的目标是,以“DESCENDING”顺序打印查询结果。但问题是,具有NULL值的行位于列表顶部..如果order by降序,如何将空行放在底部?
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;
样本结果如下
SUBCAT_ID WEB_VIEWS
Swimming Lessons 56 (null)
Medical Services 17 (null)
Mobile Phones & Tablets 39 6519
Home Furnishing & Renovation 109 4519
顺序是降序,我只是想在打印结果的底部放置带有空值的行,那么如何?
答案 0 :(得分:28)
答案 1 :(得分:7)
使用case
order by case when web_views is not null
then 1
else 2
end asc,
web_views desc;