读书人

Sql Exists最大值,该如何解决

发布时间: 2013-04-02 12:35:26 作者: rapoo

Sql Exists最大值
create table #a(
id int identity(1,1) primary key,
name varchar(20) not null
)
go

-------------------------------------------------
insert into #a
select 'A1' union
select 'B2' union
select 'A3'

select * from #a a where
not exists(select 1 from #a where a.id = id and a.Id > id)
我想取ID最大的那条记录用not exists怎么怎么查三行记录都出来了呀,要怎么写呢?

[解决办法]

引用:
if object_id('Products') is not null drop table Products
create table Products(ProductID int identity, ProductName varchar(50) , ClassID int , ClickNum int)

insert into Products ……

-->=看看
ClassID = p.ClassId and ClickNum >= p.ClickNum
[解决办法]
为啥要用not exists而不用exists呢?

读书人网 >SQL Server

热点推荐