很简单
select * form tbName a
where b='a'
and not exists (
select 1 from tbName
where B='a'
and a<a.a
)
解决方案 »
- 把null 变成‘’
- sql 语句写程序,刚入门
- 请问这个SQL怎么写?
- 刚刚换了SQL 2008 ,请教一个问题
- 如果在查询字段上创建了B+树索引,能不能提高SQL模糊查询的查询效率
- 恳求大虾帮忙,怎样把SQL Server企业版安装文件打包到自己的安装文件中?
- 在SQL Server中查询时如何把float(2.9999999)格式化成只有三位(2.999)显示?
- 在DELPHI上,用MSSQL存储过程建立BOM主从临时表
- 有SQL语句高手吗?!很简单的一条语句
- 求合并查询结果的select语句!!!在线等!!!!!
- 进销存中“采购入库”和“退货入库”设计为两个表合理还是用标志字段分开合理?
- xp上的sqlserver2000无法连接上win2000服务器上的sqlserver
DECLARE @B NVARCHAR(5)
SET @B = 'a'
SELECT * FROM tb where A IN(select MAX(A) from tb where B=@B)
insert into @t values(1,1,'a')
insert into @t values(2,1,'a')
insert into @t values(3,2,'a')
insert into @t values(4,2,'a')
insert into @t values(5,3,'a')
insert into @t values(6,3,'a')
insert into @t values(7,1,'b')
insert into @t values(8,1,'b')
insert into @t values(9,2,'b')select * from @t a where a in(select min(A) from @t where b=a.b and b='a')
where b='a'
and not exists (
select 1 from tbName
where a.b = b
and a<a.a
)
*
from
@T t
where
a in(select min(a) from @t where b=t.b) and b='a'
--换一种写法
declare @t table (id int,A int,B varchar(10))
insert into @t values(1,1,'a')
insert into @t values(2,1,'a')
insert into @t values(3,2,'a')
insert into @t values(4,2,'a')
insert into @t values(5,3,'a')
insert into @t values(6,3,'a')
insert into @t values(7,1,'b')
insert into @t values(8,1,'b')
insert into @t values(9,2,'b')select
*
from
@T t
where
B+rtrim(A) in (select min(B+rtrim(A)) from @t group by B) and b='a'