1
テーブルに売上があり、売上高と合計の割合を計算しようとしています。PostgreSQL合計サブクエリの合計と割合
WITH t1 AS (
SELECT
product_id,
sum(financial_charge_cents) as cents
FROM "account_charges"
WHERE account_id = 5
AND status = 'Charged'
GROUP BY product_id
ORDER BY cents DESC
)
SELECT
product_id,
cast(cents as money)/100.0 AS dollars,
cents/(sum(cents) OVER (PARTITION BY product_id)) as percent
FROM t1
ORDER BY dollars DESC
しかし、これはすべてのパーセントを1
に戻していますが、その理由はわかりません。
これは型の問題かどうかわかりません。
本当に機能しますか? –