我有5个带有字段名称的表。 &安培;哪个名称出现在每个表中的最大时间,然后我需要找出所有答案中哪个输出最大
答案 0 :(得分:6)
select top 1 name, count(*) from table
group by name
order by count(*) desc
答案 1 :(得分:1)
只是要添加到other response,如果有多个名称出现次数最多,那么这些行中的某些内容将起作用:
;WITH cte (Name, NoOccurrences) AS
(
SELECT Name, COUNT(Name) FROM [Table] GROUP BY Name
)
SELECT Name, NoOccurrences FROM cte
WHERE NoOccurrences = (SELECT MAX(NoOccurrences) FROM cte)