我坚持制作MySQL查询来解决问题。我试图遍历一个" sales"我试图按照累计支出总额对客户ID进行排序。
|Customer ID| Purchase price|
10 |1000
10 |1010
20 |2111
42 |9954
10 |9871
42 |6121
如果我总结了客户ID相同的购买价格,我将如何遍历表格?
期待结果如:
Customer ID|Purchase Total
10 |11881
20 |2111
42 |16075
我得:选择客户ID,总和(PurchasePrice)作为SaleTotal,来自销售,其中CustomerID =(从销售中选择不同(CustomerID))订单,由PurchaseTotal asc; 但它没有工作,因为它没有遍历CustomerID,它只是想要单个结果值......
答案 0 :(得分:5)
您需要func printPacketInfo(packet: UnsafeMutablePointer<MIDIPacket>){
// print some things
print("length", packet.memory.length)
print("time", packet.memory.timeStamp)
let len = Int(packet.memory.length)
withUnsafePointer(&packet.memory.data) { p in
let p = UnsafeMutablePointer<UInt8>(p)
for i:Int in 0 ..< len {
print(i, p[i])
}
}
}
您的客户ID:
GROUP BY
答案 1 :(得分:1)
选择CustomerID,sum(PurchasePrice)作为PurchaseTotal FROM sales GROUP BY CustomerID ORDER BY PurchaseTotal ASC;
答案 2 :(得分:1)
只需进行一些谷歌搜索,我就找到了一个完全正在做的事情的页面(我想)。我根据您的情况量身定制了以下查询。
SELECT CustomerID, SUM(PurchasePrice) AS PurchaseTotal
FROM sales
GROUP BY CustomerID
ORDER BY PurchaseTotal ASC