欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

分类聚合统计 博客分类: mysql数据库

程序员文章站 2024-03-22 20:38:40
...

 

SELECT

user_id,

SUM(CASE when tx_type='1' then tx_amount else 0 end) as charge,

SUM(CASE when tx_type='2' then tx_amount else 0 end) as withdraw

FROM

T_TX_DETAIL

WHERE

TX_STATUS = '2'

GROUP BY

USER_ID