聚合函数小记

聚合函数不使用group by 分组只会查询出一条结果
使用group by 分组后会统计不同组别的数量

select b.STATUS as status,count(distinct(a.BUYER_NICK)) as count,cast(sum(a.PAYMENT) as decimal(15,2)) as payCount 
from DT_SMS_EFFECT as a inner join DT_TRADE_INFO as b on(a.USER_ID = b.USER_ID and a.TREAD_ID = b.TRADE_ID) 
where a.USER_ID = ? and a.GMT_SMS_SEND > ? and a.PAYTIME >= ? group by status

你可能感兴趣的:(聚合函数小记)