簡體   English   中英

查詢以獲取MySQL中不同值的計數

[英]Query to get count of distinct value in MySQL

我已經在MySQL中嘗試以下查詢,但無法正常工作。

select count(*)
from (
      select count distinct(RADL_REQUEST_MSISDN)
      from rbt_activation_details_log
      where RADL_ACTIVE ='A'
      group by RADL_REQUEST_MSISDN
     );
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' 
SELECT COUNT(DISTINCT RADL_REQUEST_MSISDN)
FROM rbt_activation_details_log
WHERE RADL_ACTIVE = 'A'
GROUP BY RADL_REQUEST_MSISDN;
SELECT Count(UNIQUE(radl_request_msisdn))
FROM   rbt_activation_details_log
WHERE  radl_active = 'A'
GROUP  BY radl_request_msisdn  

根據您的查詢:

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM