OBIEE - 是不是可以在 SELECT 语句中有子查询

Posted

技术标签:

【中文标题】OBIEE - 是不是可以在 SELECT 语句中有子查询【英文标题】:OBIEE - Is it possible to have a sub query in SELECT statementOBIEE - 是否可以在 SELECT 语句中有子查询 【发布时间】:2020-03-03 05:51:23 【问题描述】:

当我添加以下行时,我收到一个错误: COUNT(select "Workforce Management - Worker Assignment Real Time"."Worker"."Person Number" FROM "Workforce Management - Worker Assignment Real Time" where "Worker"."Person Number" > 1000)

我想要做的是添加一个新列,并为人员编号 > 1000 的员工数量设置一个 COUNT。

====================

SELECT 
   0 s_0,
   "Workforce Management - Worker Assignment Real Time"."Worker"."Employee First Name" s_1,
   "Workforce Management - Worker Assignment Real Time"."Worker"."Person ID" s_2,
   "Workforce Management - Worker Assignment Real Time"."Worker"."Person Number" s_3,
   "Workforce Management - Worker Assignment Real Time"."Worker"."Person Start Date" s_4,
   "Workforce Management - Worker Assignment Real Time"."Worker"."Termination Date" s_5,
   DESCRIPTOR_IDOF("Workforce Management - Worker Assignment Real Time"."Worker"."Worker Category") s_6,
   "Workforce Management - Worker Assignment Real Time"."Worker Assignment"."Head Count" s_7,
    COUNT(select "Workforce Management - Worker Assignment Real Time"."Worker"."Person Number" FROM "Workforce Management - Worker Assignment Real Time" where "Worker"."Person Number" > 1000) s_8

FROM "Workforce Management - Worker Assignment Real Time"

Over() 的错误

Error generating view. Error getting cursor in GenerateHead
  Error Details
Error Codes: OAMP2OPY:OPR4ONWY:U9IM8TAC:U9IM8TAC:U9IM8TAC:U9IM8TAC:OI2DL65P:OI2DL65P
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. (HY000)
State: HY000. Code: 43113. [nQSError: 43113] Message returned from OBIS. (HY000)
State: HY000. Code: 27002. [nQSError: 27002] Near <(>: Syntax error (HY000)
State: HY000. Code: 26012. [nQSError: 26012] . (HY000)
SQL Issued: call NQSGetQueryColumnInfo('SELECT COUNT(CASE WHEN "Workforce Management - Worker Assignment Real Time"."Worker"."Person Number" > 1000 THEN 1 END) OVER() FROM "Workforce Management - Worker Assignment Real Time"')
SQL Issued: SELECT COUNT(CASE WHEN "Workforce Management - Worker Assignment Real Time"."Worker"."Person Number" > 1000 THEN 1 END) OVER() FROM "Workforce Management - Worker Assignment Real Time"

【问题讨论】:

【参考方案1】:

COUNT() 窗口函数与CASE 表达式一起使用:

COUNT(CASE WHEN "Workforce Management - Worker Assignment Real Time"."Worker"."Person Number" > 1000 THEN 1 END) OVER() s_8

【讨论】:

谢谢,我不得不在最后删除 OVER(),因为它给了我一个错误。此外,这仅在当前行员工的人员​​编号 > 1000 时显示,我可以更改此设置,使其显示在每一行,而不管当前行的人员编号如何? OVER() 是分析函数 COUNT() 语法的一部分:docs.oracle.com/cd/E11882_01/server.112/e41084/… 如果您在代码中按原样使用它应该没问题。消息是什么? OVER() 最后没有错。这是获取所需列的方法。如果您收到错误,则说明您没有正确使用它,或者您问题中的代码不是您的实际代码。查看如何在 Oracle 中使用它的简化演示:dbfiddle.uk/… FROM 子句不应该是:FROM "Workforce Management - Worker Assignment Real Time"."Worker"? 如果 Worker 是一个属性,那么什么是“人员编号”? “人员编号”不是表格/视图中的列吗?

以上是关于OBIEE - 是不是可以在 SELECT 语句中有子查询的主要内容,如果未能解决你的问题,请参考以下文章

是否可以在用户活动报告上创建 OBIEE 分析?

在 OBIEE 12c 中转换 @biServer.variables 的数据类型

如何在显示列之前检查 SELECT 语句是不是存在

OBIEE 和绑定变量

如何通过 OBIEE 在一列上显示某些值?

如何比较obiee中的月份?