SELECT *
FROM VB_Names
WHERE Buurt = 'Spangen'
AND Gender = 'M'
AND Gender = 'V'
GROUP BY Name
ORDER BY COUNT DESC LIMIT 6
我想从 Gender 'M' 列中获得 3 个结果,从 Gender 'V' 列中获得 3 个结果,两者都使用 DESC 计数。
SELECT *
FROM VB_Names
WHERE Buurt = 'Spangen'
AND Gender = 'M'
AND Gender = 'V'
GROUP BY Name
ORDER BY COUNT DESC LIMIT 6
我想从 Gender 'M' 列中获得 3 个结果,从 Gender 'V' 列中获得 3 个结果,两者都使用 DESC 计数。
性别不能在同一行中同时是“M”和“V”,因此此查询将不返回任何内容。相反,使用union all
:
(SELECT *
FROM VB_Names
WHERE Buurt = 'Spangen' AND Gender = 'M'
ORDER BY count DESC
LIMIT 3
) UNION ALL
(SELECT *
FROM VB_Names
WHERE Buurt = 'Spangen' AND Gender = 'V'
ORDER BY count DESC
LIMIT 3
)
AND
将您的条件更改为OR
SELECT *
FROM VB_Names
WHERE Buurt = 'Spangen'
AND (Gender = 'M' OR Gender = 'V')
GROUP BY Name
ORDER BY COUNT DESC LIMIT 6