[不是问题]我有两个表Employee(EName,ESalary,ELocation)和Locations(s.no,Location)。我想打印每个城市的员工人数。 [英] [Not a question] I have two table Employee(EName, ESalary, ELocation) and Locations(s.no, Location). I want to print number of employees in each city.
问题描述
我有两个表员工(EName,ESalary,ELocation)和地点(s.no,位置)。
我想要打印每个城市的员工人数。
喜欢......
NY 3 >
LA 4
迈阿密1
芝加哥7
布局无关紧要。实际上印刷并不重要。
我只需要 SQL查询来检索这个。
试试这个
通过ELocation从员工组中选择ELocation,COUNT(EName);
您还不清楚表模式,但假设[s.no]是表[locations]上的主键,[Location]包含名称;并且[ELocation]在[Employee]上为该表提供外键然后你想要这样的东西......
选择位置,计数(Ename)
来自位置L
LEFT OUTER JOIN 员工E ON L 。[s.no] = E.ELocation
GROUP BY 位置
请注意,我用方括号包围[s.no],因为名称中的句点(。)无效,否则
此查询应返回帖子中的预期结果
I have two table Employee(EName, ESalary, ELocation) and Locations(s.no, Location).
I want to print number of employees in each city.
Like ....
NY 3
LA 4
Miami 1
Chicago 7
Layout does not matter. Actually printing does not matter.
I just need the SQL Query to retrieve this.
try this
select ELocation ,COUNT(EName) from Employee group by ELocation;
You have not been clear about the table schemas, but assuming that [s.no] is the primary key on table [locations] and[Location] contains the name; and that [ELocation] provides the foreign key to that table on [Employee] then you want something like this...
select Location, count(Ename) from locations L LEFT OUTER JOIN Employee E ON L.[s.no]=E.ELocation GROUP BY Location
Note that I've surrounded [s.no] with square brackets as the period (.) in the name is not valid otherwise
This query should return the expected results in your post
这篇关于[不是问题]我有两个表Employee(EName,ESalary,ELocation)和Locations(s.no,Location)。我想打印每个城市的员工人数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!