到目前为止,我有这个查询
select count(*) as howMany,sum(Duration) as totalTime
from [Tmp].[dbo].[tmp2]
group by SUBSTRING(TextData,1,25)
可以很好地返回两列:howMany 和 totalTIme。我希望它还返回一个包含 SUBSTRING(TextData,1,25) 结果的列,这对于每个组都是相同的。但是我不确定如何修改查询来完成此操作。
我也想要按totalTime排序的结果,但是下面的尝试编译失败
select *
from (select count(*) as howMany,sum(Duration) as totalTime
from [Tmp].[dbo].[tmp2]
group by SUBSTRING(TextData,1,25) )
order by totalTime;