[英]A count of something inside an INNER JOIN?
Let's say I had a table of machines our employees use called machineManufacturer
, which had the columns ID
, and manufacturer
.假设我有一张我们的员工使用的机器表
machineManufacturer
,其中包含ID
列和manufacturer
列。 Then, I had another table that was added to whenever that machine was used called deviceUsage
, which has the columns ID
, and date
.然后,每当使用该机器时,我都会添加另一个名为
deviceUsage
的表,其中包含ID
和date
列。
I want to know the number of times used grouped according to manufacturer.我想知道根据制造商分组的使用次数。
I believe the answer has something to do with COUNT
and an INNER JOIN
, but I am fairly new to SQL (only took one databases class in school).我相信答案与
COUNT
和INNER JOIN
有关,但我对 SQL 相当陌生(在学校只使用了一个数据库 class)。
I have tried something like:我试过类似的东西:
SELECT manufacturer
FROM machineManufacturer
INNER JOIN deviceUsage
ON machineManufacturer.ID = deviceUsage.ID
which returns a big column of manufacturers, without any count.它返回一大列制造商,没有任何计数。 I am trying to count them and get a table like--
我想数一数,然后得到一张像——
Manufacturer: Count
Dell: 30
HP: 27
Mac: 9
Lenovo: 14
etc.
Any comments welcome.欢迎任何意见。 Thank you for your time.
感谢您的时间。
I think you want group by
:我想你想要
group by
:
SELECT MF.manufacturer, count(*)
FROM machineManufacturer MF INNER JOIN
deviceUsage D
ON MF.ID = D.ID
GROUP BY MF.manufacturer;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.