Php 选择“从单栏到多栏查询”以查询交易类型中的贷方借方

Php 选择“从单栏到多栏查询”以查询交易类型中的贷方借方,php,mysql,select,Php,Mysql,Select,我有一张桌子 id | amount | type 1 | 2000 | cr 2 | 3000 | cr 3 | 4000 | dr 我想要结果 dr | cr 4000 | 5000 使用单个MySQL选择查询 如何做到这一点?像这样: select sum(amount) as amount, type from [your table] group by type 希望有帮助。:) 提示:分组依据和总和可能重复的 select (select c

我有一张桌子

id | amount | type 
1  | 2000   | cr
2  | 3000   | cr
3  | 4000   | dr
我想要结果

dr   |  cr
4000 |  5000
使用单个MySQL
选择
查询

如何做到这一点?

像这样:

select sum(amount) as amount, type from [your table] group by type

希望有帮助。:)

提示:
分组依据
总和
可能重复的
    select (select count(amount) from table_name where type='dr') as dr,
 (select count(amount) from table_name where type='cr') as cr from table_name;