0
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 计数。

4

2 回答 2

5

性别不能在同一行中同时是“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
)
于 2014-04-28T11:59:12.473 回答
0

AND将您的条件更改为OR

SELECT *
FROM VB_Names
WHERE Buurt = 'Spangen'
    AND (Gender  = 'M' OR Gender  = 'V')
GROUP BY Name
ORDER BY COUNT DESC LIMIT 6
于 2014-04-28T12:00:21.423 回答