sql-使用 COUNT(*) OVER (PARTITION BY
发布时间:2022-06-04 11:40:41 347
相关标签: # 数据库
我想创建一个新列,其中包含基于其他 3 列的重复元素的计数。当我尝试在 group by 上添加 i_count 时,我收到以下错误 SQL 状态:42P20。
SELECT
cst,
st,
co,
COUNT(*) OVER (PARTITION BY cst,st,co ) AS count
--mean of loss by co
FROM s.tb_st , s.tb_cst , s.tb_co , erp.tb_i
WHERE st != 'te'
GROUP BY cst,st ,co, count
ORDER BY cst , st, co;
输入
cst | st | co
sal | pa | ctr
sal | pa | ctr
sal | pa | est
sal | re | ctr
sal | re | ctr
sal | re | ust
cus | pa | ctr
cus | re | ctr
cus | re | ctr
cus | re | ctr
预期产出
cst | st | co |count | lossmeanbyco
sal | pa | ctr | 2 | 2000
sal | pa | est | 1 | 5000
sal | re | ctr | 2 | 2000
sal | re | ust | 1 | 1000
cus | pa | ctr | 1 | 2000
cus | re | ctr | 3 | 2000
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报