gpt4 book ai didi

sql - Oracle 按降序排列,最后为 NULL

转载 作者:行者123 更新时间:2023-12-02 01:34:09 25 4
gpt4 key购买 nike

我的目标是按“降序”顺序打印查询结果。但问题是,具有 NULL 值的行位于列表的顶部。如果顺序是降序,如何将空行放在底部?

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

顺序是降序排列的,我只想把空值的行放在打印结果的底部,怎么办?

最佳答案

您可以使用DESC NULLS LAST来实现这一点。

这是official documentation来自甲骨文。

NULLS LAST

Specifies that NULL values should be returned after non-NULL values.

关于sql - Oracle 按降序排列,最后为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17639837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com