http://www.sqlfiddle.com/#!3/7a295/1SQL查詢得到最想要的遊戲細節
我有一個MS SQL數據庫的Visual Studio 10裏,我需要一個查詢,讓我從收藏表中最想要的遊戲,從遊戲cover_img一起幫助遊戲桌。我有查詢與第一部分工作: -
SELECT game_name,
game_platform,
Count(game_name) AS Expr1
FROM favourites
GROUP BY game_name,
game_platform
HAVING (Count(game_name) = (SELECT Max(mycount) AS Expr1
FROM (SELECT game_name,
Count(game_name) AS mycount
FROM favourites AS Favourites_1
GROUP BY game_name) AS derivedtbl_1));
,但我不能讓cover_img以匹配遊戲桌最大的遊戲,有人可以幫助我,這是我到目前爲止,但它不工作: -
SELECT favourites.game_name,
favourites.game_platform,
games.cover_img,
Count(favourites.game_name) AS Expr1
FROM games
inner join favourites
ON games.name = favourites.game_name
GROUP BY favourites.game_name,
favourites.game_platform,
games.cover_img HAVING (Count(favourites.game_name) = (SELECT
Max(mycount) AS Expr1
FROM
(SELECT game_name,
Count(game_name) AS mycount
FROM favourites AS Favourites_1
GROUP BY game_name) AS derivedtbl_1));
您使用的是什麼RDBMS? – Mureinik
@Mureinik,它是SQL Server。 – Rahul
遊戲桌上有任何一種獨特的鑰匙嗎?我相信的基本問題是,你無法通過數據庫中的二進制字段進行分組。 – Sparky