按两个条件选择并按属性拆分

时间:2017-09-14 03:33:38

标签: php sql sqlsrv

如何检索此图片中的数据:

in this image

我的数据库看起来像这样

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

1 个答案:

答案 0 :(得分:0)

详细查询:

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;