I have the following SQL query:
我有以下SQL查询:
SELECT games.id, games.GameTitle FROM games
WHERE EXISTS (
SELECT filename FROM banners
WHERE banners.keyvalue = games.id
AND banners.filename LIKE '%front%'
)
which is not quite correct for my use
这对我的使用来说不太正确
what I'd like is something like:
我想要的是:
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
)
i.e. only select when the subquery retrieves more than 1 row.
即,仅在子查询检索多于1行时选择。
2 个解决方案
#1
5
Simply like that :
就像那样:
SELECT games.id, games.GameTitle
FROM games
WHERE (
SELECT COUNT(filename)
FROM banners
WHERE banners.keyvalue = games.id AND banners.filename LIKE '%front%'
) > 1
#2
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)
#1
5
Simply like that :
就像那样:
SELECT games.id, games.GameTitle
FROM games
WHERE (
SELECT COUNT(filename)
FROM banners
WHERE banners.keyvalue = games.id AND banners.filename LIKE '%front%'
) > 1
#2
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)