我有2个表t1存储有关每个卖方的客户(C_ID)交易(M_ID)的数据,T2存储有关卖方评级的数据,我想做的是计算C_id的购买量和卖方评级。 我可以计算每个卖家的销售客户数量和总金额,但是我还需要计算客户购买的所有商品的百分比(%)
c_id | rating_cout | rating | sum | procent
1 . | 6 . | 3 . |20 . | 40%
1 . | 5. | 2 . |50 . |30%
1 . | 4 . | 1 . |30 . | 20%
SELECT
C_id,
COUNT(t1.rating) AS rating_counts,
t2.rating,
SUM(t1.amount),
count (proc) as proc-- need to do % calculation grouped by C_id and by rating
FROM
t1
JOIN
t2 ON t1.M_ID = t2.M_ID
GROUP BY C_id , t2.rating
ORDER BY 1
;
只是不知道如何计算该百分比