假設我有一個帳戶項移動表,就像mysql - 我可以從同一列中選擇值並將它們顯示在2列結果中嗎?
ACCOUNTS table
+-------+------+---------+
| title | side | balance |
+-------+------+---------+
| cash | debit| 500.0 |
+-------+------+---------+
| cash |credit| 300.0 |
+-------+------+---------+
| cash |credit| 600.0 |
+-------+------+---------+
#..... more than 10'000 debit and credit rows
我想組信用行之和借記行的總和,並顯示在不同的列他們的每一筆。
什麼,我試圖做的是總結在兩側的羣體的平衡,就像
select title, side, sum(balance) from accounts group by side
我得到行,一個爲借方金額,另一個是信貸總和,像
+-------+------+---------+
| cash | debit| 500.0 |
+-------+------+---------+
| cash |credit| 900.0 |
+-------+------+---------+
我想是獲得整個導致一個結果行,德的總和一個字段中的位和另一個字段中的信用總和。我想最終的結果是這樣的
+-------+-------+-------+
| cash | 500.0 | 900.0 |
+-------+-------+-------+
謝謝。
選擇信用額度並將其加入借方或vica的總和? – Jacobr365
@ Jacobr365謝謝。這是我首先想到的,但我做不到。你能給我一個加入同一個表的簡單例子! –