看板 Database 關於我們 聯絡資訊
假設現在有以下這個資料表 Customer Product Amount A 甲 10 A 乙 2 A 乙 5 B 丙 2 B 甲 21 C 乙 2 D 乙 6 E 丙 7 . . . . . . . . . 如果我想找出 某項product中 某個customer 買的總數量佔總數量的比重大於50%的 以上述表格為例 product 總數量 (sum(amount)) 甲 31 乙 15 丙 9 其中各個customer 的 amount佔總數量的比重如下 customer product 該客戶該產品的總數量 amount/sum(amount) A 甲 10 10/31 = 0.3xxxx A 乙 7 7/15 = 0.4xxxx B 甲 21 21/30 = 0.7 B 丙 2 2/9 = 0.2xxx C 乙 2 2/15 = 0.1xxx D 乙 6 6/15 = 0.4 E 丙 7 7/9 = 0.6xxx 查詢某項product中 某個customer 買的總數量佔總數量的比重大於50%的結果應該是 product 甲 丙 想請教大家,這樣的查詢應該如何下指令呢 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.119.145.115