select 按两个条件并按属性拆分

select by two condition and split by attribute

如何像这张图片一样检索数据:

我的数据库是这样的

SELECT trans_id, badge_id, user_id, comp_id, amount, cash, subsidy, trans_date
FROM trans_details

详情查询:

select user_id,count(1) as Txn,sum(amount),sum(cash),sum(subsidy)
from trans_details group by user_id;

总计查询:

select count(1) as Txn,sum(amount),sum(cash),sum(subsidy)
from trans_details;