我需要帮助构建我的查询来计算系统类型ID。
示例:
SystemTypeID Description Acronym
1 System1 description ABC
2 System2 description DEF
3 System3 description XYZ
我希望构建这样的东西:
Count SystemTypeID Description Acronym
21 1 System1 description ABC
100 2 System2 description DEF
67 3 System3 description XYZ
到目前为止,我知道如何做一个独特的,但我想要计算SystemTypeID的发生次数,然后将其分组:
select distinct(a.SystemTypeID),
b.Description,
b.Acronym
from operations.Systems a,
operations.SystemTypes b
where a.SystemTypeID=b.SystemTypeID
order by a.SystemType_ID;
答案 0 :(得分:1)
而不是DISTINCT
,您需要的是COUNT
和GROUP BY
SELECT COUNT(a.SystemTypeID) AS `Count`,
a.SystemTypeID,
b.Description,
b.Acronym
FROM operations.Systems a,
operations.SystemTypes b
WHERE a.SystemTypeID = b.SystemTypeID
GROUP BY a.SystemTypeID,
b.Description,
b.Acronym
ORDER BY a.SystemType_ID;