我正在尝试计算表中的条目以识别感兴趣的记录.
我正在对结果进行分组:
select code, count(1)
from data
group by code
order by count(1) desc
Run Code Online (Sandbox Code Playgroud)
因此,如果我有多个具有相同代码的行,则查询将报告代码,其中包含该代码存在的次数.
code | Count
123 3
321 2
231 1
Run Code Online (Sandbox Code Playgroud)
从表中
code | title
123 firstcode
123 first code
123 The first code
321 The second code
321 The second code
231 The third code
Run Code Online (Sandbox Code Playgroud)
我想通过为每个代码的一行显示一个(任何(可能是第一个))标题字段来指示代码所代表的内容.
我怎样才能做到这一点?
我觉得我需要做一些事情:
select code,
( select top 1 title from data d2 where d2.code = d.code
) title,
count(1)
from data d
group by ( select top 1 title from …Run Code Online (Sandbox Code Playgroud)