select top 1 a.某个字段 as 某个字段1,b.某个字段 as 某个字段2
from 表 a,表 b
order by abs(a.某个字段-b.某个字段)
from 表 a,表 b
order by abs(a.某个字段-b.某个字段)
解决方案 »
- 求助!!SharePoint2007未能创建配置数据库
- 说简单又不简单谁能搞定
- 是否可以用SQL指令实现将access文件导进sql中?怎么写
- 怎么写一个JOB 执行DTS包
- 谁有《SQL Server 2000 存储过程与XML编程》的电子书啊?
- 如何计算堵塞率
- 如何取得局域网内所有SQLServer的数据库服务器?
- 如何将sql表中数据排序后输入excel表啊
- 我sql server数据库表里面有个datetime字段,可以为空,每次我插入新记录时如果没有填就自动存为1900-1-1?
- 求助,SQL Server数据库问题(急!!!在线等待)
- top 1 中的第2项的判断?
- 每个分类(CategoriesID相同)只取出前十条记录的Sql语句怎么写
from 表 a,表 b
where a,id<>b.id
order by abs(a.某个字段-b.某个字段)
select * from 表 a
where exists(select * from 表 where left(字段,3)=left(a.字段,3))
where exists(select * from 表 where 字段<>a.字段 and left(字段,3)=left(a.字段,3))
order by 字段
declare @t table(a varchar(50))
insert @t select '380695261'
union all select '411275303'
union all select '250928829'
union all select '360831343'
union all select '411273648'
union all select '286644423'
union all select '286644423'
union all select '380693652'
union all select '312772583'
union all select '411271267'
union all select '312772511'
union all select '373276544'
union all select '363951636'
union all select '305065994'
union all select '411269945'
union all select '369506652'
union all select '395673923'
union all select '254133880'
union all select '383701153'
union all select '363950562'
union all select '344210400'
union all select '250922672'
union all select '254130526'
union all select '373274842'--查询
select * from @t a
where exists(select * from @t where a<>a.a and left(a,3)=left(a.a,3))
order by a/*--测试结果a
--------------------------------------------------
250922672
250928829
254130526
254133880
312772511
312772583
363950562
363951636
373274842
373276544
380693652
380695261
411269945
411271267
411273648
411275303(所影响的行数为 16 行)
--*/