这是我的查询
SELECT
artist.firstname
,artist.lastname
,AvgRating = AVG(painting.rating) OVER ( PARTITION BY painting.artistid )
,MaxRating = MAX(painting.rating) OVER ( PARTITION BY painting.artistid )
,MinRating = MIN(painting.rating) OVER ( PARTITION BY painting.artistid )
FROM
painting
JOIN
artist ON painting.artistid = artist.id
GROUP BY
artist.firstname
,artist.lastname
HAVING COUNT(painting.title) > 2
但是我得到这个错误:
列“ painting.ArtistId”在选择列表中无效,因为它既不包含在聚合函数中,也不包含在GROUP BY子句中。行:1
答案 0 :(得分:1)
这可能会帮助
SELECT
artist.firstname
,artist.lastname
,AvgRating = AVG(painting.rating)
,MaxRating = MAX(painting.rating)
,MinRating = MIN(painting.rating)
FROM painting
JOIN artist ON painting.artistid = artist.id
GROUP BY
artist.firstname
,artist.lastname
HAVING COUNT(painting.artistid) > 2
答案 1 :(得分:0)
您只需要将ArtistId添加到GROUP BY
。
SELECT
artist.firstname
,artist.lastname
,AvgRating = AVG(painting.rating) OVER ( PARTITION BY painting.artistid )
,MaxRating = MAX(painting.rating) OVER ( PARTITION BY painting.artistid )
,MinRating = MIN(painting.rating) OVER ( PARTITION BY painting.artistid )
FROM painting
JOIN artist ON painting.artistid = artist.id
GROUP BY
artist.firstname
,artist.lastname
,painting.artistid
HAVING COUNT(painting.title) > 2