SQL查询结果应该给出最大计数

时间:2017-09-07 13:37:20

标签: mysql

ControlTemplate

我希望结果只显示最大值,请帮帮我

1 个答案:

答案 0 :(得分:0)

根据计数对表格进行排序,然后使用LIMIT

SELECT * FROM

(SELECT count(*) rcount
    , DATE(create_date) crdate
    , fk_account_id accid
    , fk_caa_payment_pool_id poolId 
FROM  caa_payment_confirmation_hdr 
WHERE fk_caa_payment_pool_id IN 
(
    SELECT pk_caa_payment_pool_id 
    FROM caa_payment_pool 
    WHERE is_deleted = 0
) 
AND create_date >= '2017-08-01'
GROUP BY crdate
    , poolId
) A ORDER BY cnt DESC LIMIT 1