select top 1 * from table where a='1' order by b desc
但是显示在web页面上时这条记录前面会有若干空行,就是被滤到的一些记录,请问如何解决
select * from table1 where b in(select top 1 b from table1 where a='1' order by b desc)
select * from table1 where b in(select top 1 b from table1 where a='1' order by b desc) and a='1'
insert into #aa select * from talbe1 where a='1' select max(b) from #aa
select * from table1 where b = (select max(b) from table1 where a='1') and a='1'
支持 yoki(小马哥) 的回答,我試過了
select * from 表名 where B IN (select max(B) from 表名 where a=1)这个也行,yoki(小马哥)的: select * from 表名 where B in(select top 1 B from 表名 where A='1' order by B desc) and A='1'
引用(共同进步)的回复 select * from 表名 where B IN (select max(B) from 表名 where a=1)这个应该是最简单的,而且目的也能达到。但是如果数据量大的话,查询的速度可能会慢点。
TO yyy431706(共同进步) 你的查詢語句後面還是要加上and a='1',否則查到的會a=其它的東東 試驗的結果:)
where b in(select top 1 b from table1 where a='1' order by b desc)
where b in(select top 1 b from table1 where a='1' order by b desc)
and a='1'
select * from talbe1 where a='1'
select max(b) from #aa
where b = (select max(b) from table1 where a='1') and a='1'
select * from 表名
where B in(select top 1 B from 表名 where A='1' order by B desc)
and A='1'
select * from 表名 where B IN (select max(B) from 表名 where a=1)这个应该是最简单的,而且目的也能达到。但是如果数据量大的话,查询的速度可能会慢点。
你的查詢語句後面還是要加上and a='1',否則查到的會a=其它的東東
試驗的結果:)