从另一个SQL查询中选择信息

从另一个SQL查询中选择信息,sql,subquery,Sql,Subquery,我正在尝试使用SQL从已运行的查询中选择信息。我没有权利创建我知道可以解决问题的视图。我已运行以下(模糊化)查询,该查询引发了许多错误: SELECT distinct(countValue), count(countValue) FROM ( SELECT customer_identifier, count(distinct(2nd_customer_identifier)) AS countValue FROM table GROUP BY customer_identifie

我正在尝试使用SQL从已运行的查询中选择信息。我没有权利创建我知道可以解决问题的视图。我已运行以下(模糊化)查询,该查询引发了许多错误:

SELECT
  distinct(countValue),
  count(countValue)
FROM
(
  SELECT customer_identifier, count(distinct(2nd_customer_identifier)) AS countValue FROM table GROUP BY customer_identifier;
)
GROUP BY
  distinct(countValue)
子查询(以下)正在尝试获取每个客户的唯一收款人计数:

SELECT 
    customer_identifier, 
    count(distinct(2nd_customer_identifier)) AS countValue 
FROM table
GROUP BY aid
使用它的主查询试图从上表中获取计数的值,并计算每个值发生的次数


如果有任何帮助,我们将不胜感激。

您能用以下内容替换它吗?这将告诉您有多少多个付款人的情况

SELECT 
    CountValue, 
    count(countValue) TotalRecords
FROM 
  ( 
    SELECT 
        customer_identifier, 
        count(distinct([2nd_customer_identifier])) AS countValue 
    FROM table 
    GROUP BY customer_identifier
  ) a
GROUP BY countValue ;
输出将告诉您以下内容:

共有25个单一付款人账户

共有17个两个付款人账户

共有9个三个付款人账户

等等


如果这不是你想要的,请编辑你的问题来描述你想要的结果

谢谢!删除不同的文件可以消除错误