我正在努力在雪花模式中创建一个语句。我需要显示所有产品和相关曲目的列表,但还需要计算每个曲目附有多少词曲作者。我的桌子是:
Table: PRODUCT
-PRODUCT_ID
-ALBUM_ARTIST
-ALBUM_TITLE
Table: SONGWRITER
-SONGWRITER_ID
-FIRSTNAME
-LASTNAME
Table: SONG_SONGWRITER
-SONGWRITER_ID
-TRACK_ID
-OWNERSHIP_SHARE
Table: TRACK
-TRACK_ID
-PRODUCT_ID
-TRACK_ARTIST
|TRACK_NAME
我尝试了以下操作,但是由于 group by 子句而出错。有没有人有什么建议?
SELECT prod.*, tra.TRACK_NAME,count(*) AS "Number of Songwriters"
FROM PRODUCT prod
INNER JOIN TRACK tra
ON tra.PRODUCT_ID=prod.PRODUCT_ID
INNER JOIN SONG_SONGWRITER ssw
ON ssw.TRACK_ID = tra.TRACK_ID
GROUP BY prod.PRODUCT_ID