目前尚不清楚你的實際問題是什麼。如果您知道如何使用PHP中的SQL,您當然知道如何讀取結果,並知道如何將數據添加到數組中。因此,您可以讀取按照saleID排序的表數據並在循環中填充數組。
無論如何,它可以幫助你,讓每一個saleID記錄,而不是:
select saleid, st.price as subtotal_price, t.price as tax_price
from (select * from transactiontable where producttype = 'subtotal') st
join (select * from transactiontable where producttype = 'tax') t using (saleid);
這是標準的SQL。如果您的DBMS不支持USING
子句,則必須改爲使用ON
。
這是你的樣品和查詢結果:
TransactionID | saleID | productType | Price
1 | 1001 | subtotal | 19.50
2 | 1001 | tax | 3.11
3 | 1002 | subtotal | 19.50
4 | 1002 | tax | 3.11
結果:
saleid | subtotal_price | tax_price
1001 | 19.50 | 3.11
1002 | 19.50 | 3.11
你能添加想要的結果嗎? (格式與現有表格數據相同。) – jarlh
'每個匹配數字的SaleID ......這是什麼意思? –
'由saleID'從select_table組中選擇saleID,SUM(Price)? – bassxzero