select * from [table] t where not exists(select * from [table] where ([out]-[in])>(t.[out]-t.[in])
if object_id('[table]') is not null drop table [table] go create table [table]([id] int,[in] int,[out] int) insert [table] select 1,10,20 union all select 2,10,30 union all select 3,10,40select * from [table] t where not exists(select * from [table] where ([out]-[in])>(t.[out]-t.[in]))--测试结果: /* id in out ----------- ----------- ----------- 3 10 40(所影响的行数为 1 行) */
select top 1 * from table order by out-in desc
select top 1 * from table order by [out]-[in] desc
select top 1 * from table order by [out] - [IN] desc
select top 1 * from table order by [out] - [IN] desc
from table
order by out desc
*
from
[table] t
where
not exists(select * from [table] where ([out]-[in])>(t.[out]-t.[in])
go
create table [table]([id] int,[in] int,[out] int)
insert [table]
select 1,10,20 union all
select 2,10,30 union all
select 3,10,40select
*
from
[table] t
where
not exists(select * from [table] where ([out]-[in])>(t.[out]-t.[in]))--测试结果:
/*
id in out
----------- ----------- -----------
3 10 40(所影响的行数为 1 行)
*/
from table
order by out-in desc
from table
order by [out]-[in] desc
select top 1 *
from table
order by [out] - [IN] desc
from table
order by [out] - [IN] desc
from tb
order by out-in desc