如何返回按NULL和NOT NULL分组的记录? [英] How do I return my records grouped by NULL and NOT NULL?

查看:127
本文介绍了如何返回按NULL和NOT NULL分组的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有processed_timestamp列的表-如果记录已被处理,则该字段包含其处理的日期时间,否则为空.

I have a table that has a processed_timestamp column -- if a record has been processed then that field contains the datetime it was processed, otherwise it is null.

我想编写一个返回两行的查询:

I want to write a query that returns two rows:

NULL        xx -- count of records with null timestamps
NOT NULL    yy -- count of records with non-null timestamps

有可能吗?

更新:该表非常大,因此效率很重要.我可以只运行两个查询来分别计算每个总数,但是如果可以避免的话,我想避免两次击中该表.

Update: The table is quite large, so efficiency is important. I could just run two queries to calculate each total separately, but I want to avoid hitting the table twice if I can avoid it.

推荐答案

Oracle:

按nvl2(字段,"NOT NULL","NULL")分组

group by nvl2(field, 'NOT NULL', 'NULL')

这篇关于如何返回按NULL和NOT NULL分组的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆