You need to enable JavaScript to run this app. 基于Ridge Gallery视图:COUNT函数统计artistid异常
优惠活动
大模型
产品
解决方案
定价
更多

基于Ridge Gallery视图:COUNT函数统计artistid异常

问题分析与解决方案

你的SQL里group by artistid, datesold是按艺术家ID+销售日期分组统计,所以得到的是每个艺术家在不同日期的销售次数,只有当同一个艺术家在同一天有多条销售记录时,count才会大于1。如果要统计每个艺术家的总销售次数,需要调整分组逻辑:

方案1:仅统计每个艺术家的总销售次数

去掉datesold字段和分组条件,只按artistid分组:

select artistid, count(artistid) as total_sales
from tutorials.work w 
join( 
    select workid, datesold
    from tutorials.trans t  
    where datesold is not null
)t on w.workid = t.workid  
group by artistid  
order by artistid;  

方案2:保留销售日期同时显示总次数

如果需要保留datesold信息,同时展示每个艺术家的总销售次数,可以用窗口函数:

select 
    artistid,
    datesold,
    count(artistid) over(partition by artistid) as total_sales
from tutorials.work w 
join( 
    select workid, datesold
    from tutorials.trans t  
    where datesold is not null
)t on w.workid = t.workid  
order by artistid;  

内容的提问来源于stack exchange,提问作者Wei hao Sin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 20:04:51