表
ITEM | SKU | QUANT | ITEM LANDING
-----+-------+---------+-----------------
ABC | A-B-C | 5 | 500
ABC | A-B-C | 10 | 400
DEF | D-E-F | 5 | 200
GHI | G-H-I | 6 | 300
JKL | J-K-L | 5 | 800
JKL | J-K-L | 10 | 600
RESULT
ITEM NAME | ITEM SKU | QUANT | Weighted Average
----------+-----------+--------+---------------------
ABC | A-B-C | 15 | 433.33
DEF | D-E-F | 5 | 200
GHI | G-H-I | 6 | 300
JKL | J-K-L | 15 | 666.66
我想计算重复项目的加权平均值 ((首次登陆*数量)+(第二次登陆*数量))/(总和(数量)
答案 0 :(得分:7)
SELECT ITEMNAME, ITEMSKU, SUM(QUANT), SUM(QUANT * ITEM_LANDING) / SUM(QUANT)
FROM <YourTable>
GROUP BY ITEMNAME, ITEMSKU
答案 1 :(得分:2)
试试这个......
SELECT item_name AS 'ITEM NAME',
item_sku AS ' ITEM SKU',
SUM(quant) AS 'QUANT',
(SUM(quant*item_landing)/sum(quant)) AS 'ITEM LANDING'
FROM items
GROUP BY item_name;