1. 程式人生 > >mysql分組後計算分組的組數和根據某個欄位去重計數

mysql分組後計算分組的組數和根據某個欄位去重計數

計算分組的組數

SELECT count(1) from (select  COUNT(1) as sum FROM TM_APP_MAIN A INNER JOIN TM_APP_PRIM_APPLICANT_INFO B ON A.APP_NO= B.APP_NO  LEFT JOIN TM_BLACK_LIST C on A.APP_NO= C.APP_NO where  A.ORG = 9982 group by C.APP_NO,C.LIST_LEVEL having (select count(*) from TM_BLACK_LIST) >0) ali;

根據某個欄位去重計數

SELECT  COUNT(DISTINCT B.APP_NO ) FROM TM_APP_PRIM_APPLICANT_INFO B where B.ORG = 99