易截截图软件、单文件、免安装、纯绿色、仅160KB

求一SQL - MS-SQL Server / 基础类

表结构如下
字段1 字段2 字段3
1 aaa bbaaa
2 bbaaa bbaaa
3 ccc bbccc
4 bbccc bbccc
5 ddd bbddd

要求结果如下:

2 bbaaa bbaaa
4 bbccc bbccc
5 ddd bbddd

字段3相同的记录取 字段2长的那条!

谢谢了
SQL code:
select *
from tb t
where not exists(select 1 from tb where col3=t.col3 and len(col2)>len(t.col2))



就是楼上的了

引用
SQL code
select *
from tb t
where not exists(select 1 from tb where col3=t.col3 and len(col2)>len(t.col2))


up


正解 回复有幾分

谢谢楼上几位 结贴


相关问答:

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

求一SQL写法 - MS-SQL Server / 基础类

id                           url                   rank     ......

SQL语句问题 - MS-SQL Server / 疑难问题

请教高手:
 以下是数据库中的三条记录,英文为字段名称  
  id planname TaskBeginTime Status
329 2010年03 ......

mysql区没高手 - MS-SQL Server / 基础类

我觉得mysql和sqlserver有共同的地方:
有个问题是关于表的锁问题:
进程A 进程B
select * from user where id in lock share mode(共享锁)
&nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号