2016-12-09 11 views
-1

私はテーブル選択クエリ

id | amount | type 
1 | 2000 | cr 
2 | 3000 | cr 
3 | 4000 | dr 

を持っている私は、単一のMySQL SELECTクエリを使用して

dr | cr 
4000 | 5000 

を結果します。

これを行う方法?このような

+0

ヒント: 'group by'と' sum' – Blank

+0

[mysqlを使って各行の総量を取得するにはどうすればいいですか?](http://stackoverflow.com/questions/41055855/how-can-i -get-total-amount-each-row-using-mysql) –

答えて

0
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; 

はそれがお役に立てば幸いです。 :)

0

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