gpt4 book ai didi

mysql - 如果没有 GROUP BY 子句,则将 GROUP 列(MIN()、MAX()、COUNT()...)与没有 GROUP 列的混合是非法的。玛丽亚数据库错误

转载 作者:行者123 更新时间:2023-11-29 15:23:03 30 4
gpt4 key购买 nike

我正在使用 MariaDB IMDB 电影数据集,我试图解决以下问题。电影表包含 id、名称、排名和年份列

A decade is a sequence of 10 consecutive years. For example, say in your database you have movie information starting from 1965. Then the first decade is 1965, 1966, ..., 1974; the second one is 1967, 1968, ..., 1976 and so on. Find the decade D with the largest number of films and the total number of films in D.

当我尝试执行以下查询时,出现以下错误
选择
SUM(T3.MOVIE_PER_YEAR),
T3.GROUP_PER_DECADE

(
选择
CEIL(T2.ROW_NUM/10) AS GROUP_PER_DECADE,
T2.MOVIE_PER_YEAR,
T2.年

(
选择
ROW_NUMBER() OVER (ORDER BY T1.YEAR ASC) AS row_num,
T1.MOVIE_PER_YEAR,
T1.年

(选择
COUNT(M.id) AS MOVIE_PER_YEAR
,我的耳朵

电影 M
通过...分组
我的耳朵
)T1
)T2
)T3 按 GROUP_PER_DECADE 分组;

错误:-

Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

Oracle DB 中正在运行相同类型的查询。
http://sqlfiddle.com/#!4/cdf8e3/9

请帮我解决这个问题。

最佳答案

任务不能更简单地完成吗:

SELECT FLOOR(year / 10) * 10 AS decade,
COUNT(*) AS movies_per_decade
FROM Movies

例如,假设 1980 年至 1989 年都是“1980 十年”。

如果您想要“几十年前”,请更改为类似 FLOOR(YEAR(NOW() -year)/10) AS数十年前

(这适用于任何版本的 MySQL/MariaDB。)

关于mysql - 如果没有 GROUP BY 子句,则将 GROUP 列(MIN()、MAX()、COUNT()...)与没有 GROUP 列的混合是非法的。玛丽亚数据库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59243088/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com