我有一个名为Employee
的表,其中包含字段 Id,地址,phone_no,薪水,date_of_joining 和流。它只包含一行和字段:
NULL
个值。 我希望输出为包含NULL
值的字段,即地址, phone_no 和 date_of_joining 。这需要在Oracle SQL中执行。我不知道如何去做。
输入:
EMPLOYEE
Id Address phone_no salary date_of_joining stream
101 NULL NULL 8,00,000 NULL Big Data
输出:
Address,
phone_no,
date_of_joining
答案 0 :(得分:1)
您可以明确地执行此操作:
select 'Id' from t where Id is null union all
select 'Address' from t where Address is null union all
select 'phone_no' from t where phone_no is null union all
select 'salary' from t where salary is null union all
select 'date_of_joining' from t where date_of_joining is null union all
select 'stream' from t where stream is null;
答案 1 :(得分:0)
你可以这样做(与戈登的解决方案相同,但在一个记录中):
Select Id,
case when phone_no is null then 'phone_no, ' else '' end ||
case when Address is null then 'Address, ' else '' end ||
case when date_of_joining is null then 'date_of_joining' else '' end as Null_values
from t;