1

我已经在 MySQL 中尝试了以下查询,但没有工作。

select count(*)
from (
      select count distinct(RADL_REQUEST_MSISDN)
      from rbt_activation_details_log
      where RADL_ACTIVE ='A'
      group by RADL_REQUEST_MSISDN
     );
4

4 回答 4

3
select count(distinct column_whose_distinct_values_you_want_to_count) 
from rbt_activation_details_log 
where RADL_ACTIVE ='A' 
group by RADL_REQUEST_MSISDN

您正在对同一列进行分组和计数,因此这将始终为您1提供结果。

编辑:

然后简单地省略 group by 子句

select count(distinct RADL_REQUEST_MSISDN) 
from rbt_activation_details_log 
where RADL_ACTIVE ='A' 
于 2013-08-23T14:59:14.523 回答
1
SELECT COUNT(DISTINCT RADL_REQUEST_MSISDN)
FROM rbt_activation_details_log
WHERE RADL_ACTIVE = 'A'
GROUP BY RADL_REQUEST_MSISDN;
于 2013-08-23T15:00:05.057 回答
1
SELECT Count(UNIQUE(radl_request_msisdn))
FROM   rbt_activation_details_log
WHERE  radl_active = 'A'
GROUP  BY radl_request_msisdn  
于 2013-08-23T15:00:25.190 回答
1

根据您的查询:

select count(*) 
from
    (select count distinct(RADL_REQUEST_MSISDN)
    from rbt_activation_details_log
    where RADL_ACTIVE ='A' group by RADL_REQUEST_MSISDN);

显示为您要检索未按 radl_request_msisdn 分组的所有不同计数。如果是这样,那么您以这种方式重写您的查询:

    select count distinct(RADL_REQUEST_MSISDN)
    from rbt_activation_details_log
    where RADL_ACTIVE ='A';

相反,如果您想分组,查询将是:

    select count distinct(RADL_REQUEST_MSISDN)
    from rbt_activation_details_log
    where RADL_ACTIVE ='A' group by RADL_REQUEST_MSISDN;
于 2013-08-23T15:01:13.760 回答