-1
私はテーブル選択クエリ
id | amount | type
1 | 2000 | cr
2 | 3000 | cr
3 | 4000 | dr
を持っている私は、単一のMySQL SELECT
クエリを使用して
dr | cr
4000 | 5000
を結果します。
これを行う方法?このような
私はテーブル選択クエリ
id | amount | type
1 | 2000 | cr
2 | 3000 | cr
3 | 4000 | dr
を持っている私は、単一のMySQL SELECT
クエリを使用して
dr | cr
4000 | 5000
を結果します。
これを行う方法?このような
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;
はそれがお役に立てば幸いです。 :)
:
select sum(amount) as amount, type from [your table] group by type
ヒント: 'group by'と' sum' – Blank
[mysqlを使って各行の総量を取得するにはどうすればいいですか?](http://stackoverflow.com/questions/41055855/how-can-i -get-total-amount-each-row-using-mysql) –