如果我有以下数据:
match '/', to: 'blog_posts#index', constraints: { subdomain: 'blog' }, via: [:get, :post, :put, :patch, :delete]
我按K1& amp;分区我的数据K2,所以我可以得到总计数:
K1 K2 V3
100 A C
100 A C
100 A D
200 B D
200 B D
200 B C
哪个收益率:
count(V3) over (partition by K1, K2)
如何获取引用行中值的分区的小计?结果将是:
K1 K2 V3 Total
100 A C 3
100 A C 3
100 A D 3
200 B D 2
200 B E 2
答案 0 :(得分:2)
SELECT
K1,
K2,
V3,
count(V3) over (partition by K1, K2) as Total,
count(V3) over (partition by K1, K2, V3) as Subtotal
FROM DataTable