Mysql 在SQL中查找员工超过10人的门店
假设我有一个表Mysql 在SQL中查找员工超过10人的门店,mysql,sql,Mysql,Sql,假设我有一个表stores\u employees,它有两列: store_id, employee_id 我怎样才能找到一家员工超过10人的商店?最好的方法是什么?您将在HAVING子句和groupby store\u id select store_id from stores_employees group by store_id having count(employee_id) > 10 看 如果要包括员工总数,则可以使用: select store_id, count(e
stores\u employees
,它有两列:
store_id, employee_id
我怎样才能找到一家员工超过10人的商店?最好的方法是什么?您将在
HAVING
子句和groupby store\u id
select store_id
from stores_employees
group by store_id
having count(employee_id) > 10
看
如果要包括员工总数,则可以使用:
select store_id, count(employee_id) TotalEmployees
from stores_employees
group by store_id
having count(employee_id) > 10
从逻辑上考虑这个问题,您需要从stores\u emloyes表中统计store\u id和employee\u id的实例,其中count大于10 我发现这是学习mysql最有效的方法,而不是从网站上复制 您可能使用的关键字:
SELECT
FROM
ORDER BY
BETWEEN
如果这个问题更难,你就不会有答案,但人们会问你像约翰一样尝试了什么,但简单的分数会让你快速得到答案。在将来,试着发布你尝试过的东西,或者至少读过关于它的文章。同意我的@Luis,-1。
SELECT
FROM
ORDER BY
BETWEEN