我试图找出组中表中最常出现的值。 这适用于SQL
Part | location | PartDesc
-----+----------+-------------
A | 2 | Part A
A | 2 | Part A
A | 2 | Part A
A | 1 | Part A
A | 1 | Part A
B | 1 | Part B
B | 2 | Part B
所以输出需要显示
Part | Location | PartDesc | Occurrence
-----+----------+----------+--------------
A | 2 | Part A | 3
A | 1 | Part A | 2
B | 1 | Part B | 1
B | 2 | Part B | 1
到目前为止我已经
了Select Part, count(*) as occurrence
from table1
group by Part
order by count(*desc)
答案 0 :(得分:3)
SELECT
Part,
Location,
PartDesc,
COUNT(*) AS Occurrence
FROM
table1
GROUP BY
Part,
Location,
PartDesc
ORDER BY
Occurrence DESC
感谢。