0
什麼是獲取數據了,從下表中的最好的SQL如下選擇數據
例表
id name buyer amt
1 per disney 10
1 per marie 12
1 per clarence 11
2 pella Magnus 5
2 pella Olof 2
2 pella Asa 4
3 chris Lotta 6
3 chris Wayne 3
3 chris Brad 5
數據輸出:
Customer Name : Per
disney 10
marie 12
clarence 11
Total 33
Customer Name : pella
Magnus 5
Olof 2
Asa 4
Total 11
Customer Name : Chris
Lotta 6
Wayne 3
Brad 5
Chris 14
所以最後它的名稱在頂部,並且每個買家對於該賣家和每筆交易以及最終的總數。
我想出了這個SQL查詢,但它很粗糙。
select name, supplier, amt, (select sum(amt) from transact where name = t.name)as total from transact t
這不是除了存儲過程可能的。您也可以使用PHP代碼從記錄集中獲得總和。 – Sadat 2010-10-23 13:17:25