该错误发生在我尝试SUM(genre) AS "Total"
的第5行上。
我尝试将convert
设置为genre
的{{1}}或将int
设置为cast
,都导致操作错误。
int
答案 0 :(得分:1)
如果您想要所有类型的合计,请使用窗口函数:
SELECT CAST(genre AS CHAR(20)) AS Genre,
COUNT(*) as cnt,
SUM(COUNT(*)) OVER () as total
FROM title_genre
GROUP BY genre
ORDER BY "Count" DESC;
对于比例,您将使用:
(COUNT(*) * 1.0 / SUM(COUNT(*)) OVER ()) as proportion