Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL统计列中的所有行_Sql_Oracle_Count_Rows_Analytic Functions - Fatal编程技术网

SQL统计列中的所有行

SQL统计列中的所有行,sql,oracle,count,rows,analytic-functions,Sql,Oracle,Count,Rows,Analytic Functions,我需要在ORACLE SQL中计算所有行并将其写入列。 它看起来应该是这样的(向左看,向右看): 我尝试过数(*)OVER(PARTITION BY),UNION等等 提前感谢。您可以使用窗口功能: select a, count(a) over () as cnt_a, b, count(b) over () as cnt_b, c, count(c) over () as cnt_c, d, count(d) over () as cnt_d fro

我需要在ORACLE SQL中计算所有行并将其写入列。 它看起来应该是这样的(向左看,向右看):

我尝试过数(*)OVER(PARTITION BY),UNION等等


提前感谢。

您可以使用窗口功能:

select a, count(a) over () as cnt_a,
       b, count(b) over () as cnt_b,
       c, count(c) over () as cnt_c,
       d, count(d) over () as cnt_d
from t;
   

您可以使用聚合查询和交叉联接来完成此操作。如果你有大量的数据,将其与Gordon Linoff的答案中所示的分析函数方法进行比较会很有趣;聚合方法从基表读取数据两次(这将花费更多的时间),但聚合函数的计算速度要比分析函数快得多,即使它们执行相同的操作

大概是这样的:

select a, cnt_a, b, cnt_b, c, cnt_c, d, cnt_d
from   t cross join
       ( select count(a) cnt_a, count(b) cnt_b, count(c) cnt_c, count(d) cnt_d
         from   t
       )
;

谢谢。我不知道一个没有被表达式分割的OVERpossible@Pohly91 . . . 在这种情况下,它引用整个结果集。
select a, cnt_a, b, cnt_b, c, cnt_c, d, cnt_d
from   t cross join
       ( select count(a) cnt_a, count(b) cnt_b, count(c) cnt_c, count(d) cnt_d
         from   t
       )
;