SQL Compact中替换为最大值(文本字段)

SQL Compact中替换为最大值(文本字段),sql,sql-server,sql-server-ce,aggregate-functions,Sql,Sql Server,Sql Server Ce,Aggregate Functions,我想用sql compact执行类似于MAX(textfield)的操作,但由于sql compact 4不支持这种操作,我需要找到另一种解决方案。 下面的查询适用于SQL Server,当聚合中只有一个参考行时,它会显示一条注释(col3) -- create sample data: create table #test(col1 int, col2 int, col3 nvarchar(100)) insert into #test select 1,1,'' union select 1

我想用sql compact执行类似于MAX(textfield)的操作,但由于sql compact 4不支持这种操作,我需要找到另一种解决方案。 下面的查询适用于SQL Server,当聚合中只有一个参考行时,它会显示一条注释(col3)

-- create sample data:
create table #test(col1 int, col2 int, col3 nvarchar(100))
insert into #test
select 1,1,'' union
select 1,2,'' union 
select 2,1,'comment'
这就是我尝试过的:

select col1, case when count(*) = 1 then max(col3) else null end, count(*) from #test
group by col1
drop table #test
结果

1   NULL    2
2   comment 1
一种可能的解决方案是使用子查询,但这样做成本会很高吗

select col1, 
case when count(*) = 1 
then (select top 1 col3 from #test t2 where t.col1=t2.col1) 
else null end, 
count(*)

我对col3上的分组不感兴趣,因为这会导致预期解决方案的性能不佳,因为它有更多的列和更多的数据。。