Sql 组合多个结果并选择非null值,或者如果所有结果返回null,则分配null
我有一个观点,记录如下: 我希望像这样查询并返回报告的结果(没有任何BI工具可用,仅使用SSM): 我试过:Sql 组合多个结果并选择非null值,或者如果所有结果返回null,则分配null,sql,sql-server,tsql,reporting,Sql,Sql Server,Tsql,Reporting,我有一个观点,记录如下: 我希望像这样查询并返回报告的结果(没有任何BI工具可用,仅使用SSM): 我试过: select distinct A.Document_Title, A.First_Reviewer, A.Second_Reviewer, A.Third_Reviewer, (select B.First_review from View as B where B.Title = A.Title) as First_Review, (select B.Second_review
select distinct A.Document_Title, A.First_Reviewer, A.Second_Reviewer, A.Third_Reviewer,
(select B.First_review from View as B where B.Title = A.Title) as First_Review,
(select B.Second_review from View as B where B.Title = A.Title) as Second_Review,
(select B.Third_review from View as B where B.Title = A.Title) as Third_Review
From
View A
我得到的错误是因为我的子查询返回多个结果,我也尝试过使用Coalesce,但意识到它用于组合多个列。
感谢您的帮助。谢谢。您似乎只需要一个
分组:
select a.document_title,
a.first_reviewer, a.second_reviewer, a.third_reviewer,
max(first_review) as first_review,
max(second_review) as second_review,
max(third_review) as third_review
from viewA a
group by a.document_title, a.first_reviewer, a.second_reviewer;
你的观点可能是错误的。此聚合可能会发生在视图中。如果它使用pivot
,那么查询可能会保留在一个不必要的列中。基于大量证据,我删除了plsql标记。这里使用的逻辑有点奇怪。我会复制一份视图,并对其进行编辑,以准确返回您想要的内容。