当前位置: 代码迷 >> Sql Server >> Sql Exists最大值,该如何解决
  详细解决方案

Sql Exists最大值,该如何解决

热度:98   发布时间:2016-04-24 23:10:23.0
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呢?
  相关解决方案