简体   繁体   English

具有计数功能的个案陈述

[英]Case Statement With Count Function

How would one write a Case Statement with a count greater than one? 如何编写计数大于1的Case语句? The below is what I have so far: I'm receiving an invalid identifier. 以下是我到目前为止:我收到的标识符无效。

Select *, CASE WHEN COUNT(X.id ) >1 THEN X 
  ELSE  isnull END AS testing 
 from TestTable

Thanks for the comments. 感谢您的评论。 I was able to work through my problem as I'm new to Oracle. 我是Oracle的新手,因此能够解决我的问题。

The correct statement would be: 正确的陈述是:

Select *, CASE WHEN COUNT(X.id ) >1 THEN 'X' 
  ELSE '' END AS testing 
 from TestTable

Group by *

COUNT itself is an aggregate function that you have to use with GROUP BY. COUNT本身是一个必须与GROUP BY一起使用的聚合函数。 But you can also use it as an analytic function: 但是您也可以将其用作分析功能:

SELECT t.*, CASE WHEN COUNT(t.id) OVER(PARTITION BY ...) > 1 THEN 'X'
ELSE '' END AS testing
FROM TEST_TABLE

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

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