子查询返回多行mysql错误

时间:2017-08-21 13:29:18

标签: mysql

帮我编写查询,选择供应商名称大于2的城市名称

ID   Name      City   emp_count  vendor
'1'  'Sprox'  'RAJ'  '23'       'es'
'2'  'Raj'    'RAJ'  '4'        'es'
'3'  'juli'   'BAN'  '4'        'bob'
'4'  'crafer' 'BAN'  '5'        'axe'

查询:

select city from test.org where 2= (select  count( vendor )from test.org group by vendor) ;

2 个答案:

答案 0 :(得分:0)

这个怎么样 -

SELECT city, COUNT(vendor)
FROM test.org
GROUP BY city
HAVING COUNT(vendor) > 2;

答案 1 :(得分:0)

select city,vendor, count(*)
from t
group by city,vendor
having count(*) >= 2