我是SQL的新手,已阅读过很多来源,它只是告诉我使用HAVING代替.替代方案中是否有更多的解决方案或理由?
另外,在HAVING子句中使用聚合函数是不是一个错误?这与在where子句中使用one有什么不同?
我只需要显示至少有两个标题的类型.
我的标题表:
Titles
------
TitleID, ArtistID, Title, StudioID, Genre
Run Code Online (Sandbox Code Playgroud)
我的曲目表:
Tracks
------
TitleID, TrackNum, TrackTitle
Run Code Online (Sandbox Code Playgroud)
到目前为止这是我的代码:
select t.genre from titles t
join tracks tr
on (tr.titleid = t.titleid)
having count(tr.tracktitle) > 1;
Run Code Online (Sandbox Code Playgroud)
我不知道当前的代码是否正确回答了所描述的问题.