简体   繁体   English

Oracle 案例报表查询

[英]Oracle Case Statement Query

I am working on an Oracle Query to find if Diagnostic Pack is installed.我正在处理 Oracle 查询以查找是否安装了诊断包。 Query is working fine.查询工作正常。

Select case when currently_used = 'TRUE' then 1
else 0
end DIAGNOSTICS_package
from dba_feature_usage_statistics
where name like '%Diagnostic Pack%'
and CURRENTLY_USED = 'TRUE'

In the Output I need to add another Column Installed.在 Output 我需要添加另一个安装的列。 So if currently_used = 'TRUE' I need the output to be displayed as below.因此,如果 current_used = 'TRUE' 我需要 output 显示如下。

DIAGNOSTICS_package INSTALLED
1                   YES

I am running into an issue with the INSTALLED Column in the case statement.我在 case 语句中遇到了 INSTALLED 列的问题。 Please advise.请指教。

Thanks谢谢

The simplest answer to your question is, just add another CASE expression for the second column:您的问题的最简单答案是,只需为第二列添加另一个 CASE 表达式:

Select case when currently_used = 'TRUE' then 1
else 0
end DIAGNOSTICS_package,
case when currently_used = 'TRUE' then 'YES' else 'NO' end INSTALLED
from dba_feature_usage_statistics
where name like '%Diagnostic Pack%'
and CURRENTLY_USED = 'TRUE'

I don't really get why you want two columns that tell you the same thing in different ways.我真的不明白为什么你想要两列以不同的方式告诉你同样的事情。

I also don't get why you need a CASE statement at all, since you have and CURRENTLY_USED = 'TRUE' as part of the query conditions.我也不明白为什么你需要 CASE 语句,因为你有and CURRENTLY_USED = 'TRUE'作为查询条件的一部分。

But maybe there is a larger context where these things make sense.但也许在更大的背景下,这些事情是有意义的。

Based on your where clause, you don't need a case expression:根据您的where子句,您不需要case表达式:

Select 1 as DIAGNOSTICS_package,
       'YES' as INSTALLED
from dba_feature_usage_statistics
where name like '%Diagnostic Pack%' and
      CURRENTLY_USED = 'TRUE'

You are already filtering on CURRENTLY_USED = 'TRUE' .您已经在CURRENTLY_USED = 'TRUE'上进行过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM