我有以下SQL查询:
SELECT games.id, games.GameTitle FROM games
WHERE EXISTS (
SELECT filename FROM banners
WHERE banners.keyvalue = games.id
AND banners.filename LIKE '%front%'
)
这对我的使用来说不太正确
我想要的是:
SELECT games.id, games.GameTitle
FROM games WHERE EXISTS (
COUNT(SELECT filename FROM banners
WHERE banners.keyvalue = games.id AND banners.filename LIKE '%front%') > 1
)
即。仅在子查询检索多于一行时选择。
答案 0 :(得分:5)
就是这样:
SELECT games.id, games.GameTitle
FROM games
WHERE (
SELECT COUNT(filename)
FROM banners
WHERE banners.keyvalue = games.id AND banners.filename LIKE '%front%'
) > 1
答案 1 :(得分:2)
SELECT games.id, games.GameTitle
FROM games
WHERE EXISTS (SELECT COUNT(filename)
FROM banners
WHERE banners.keyvalue = games.id
AND banners.filename LIKE '%front%'
HAVING COUNT(filename)>1)