先排序到临时表之后在分组。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!-- 首次充值相关信息 -->
<sql id="firstChargeInfoSQL">
SELECT
companyid as companyid ,
chargeid as firstChargeId,
addtime as firstChargeT
ime,
currentmoney as firstChargeAmount
FROM
(
SELECT
companyid,
chargeid,
addtime,
currentmoney
FROM ${database_51p2badmin}.pb_bchargelog
WHERE status = 2 ORDER BY addtime ASC
) temp
GROUP BY companyid
</sql >