查询分组求和的最大值

求交易总额的最大值两种方法:

SELECT c.merchant_no,SUM(c.transaction_amount) AS tt FROM mer_detail c WHERE c.created_date >"2020-09-01" GROUP BY c.merchant_no ORDER BY tt DESC LIMIT 1;

SELECT MAX(dd.tt) from (SELECT c.merchant_no,SUM(c.transaction_amount) AS tt FROM mer_detail c WHERE c.created_date >"2020-09-01" GROUP BY c.merchant_no ) as dd ;

查询重复数据:

SELECT * FROM clear_mer_detail c GROUP BY c.transaction_no  HAVING COUNT(c.transaction_no)>1  ORDER BY c.created_date DES

 

posted @ 2020-09-09 15:03  pandaly  阅读(394)  评论(0编辑  收藏  举报