最优?什么概念?
按你的提示写出来速度一定不是最优的。declare @Temp table (id int)insert @Temp
select id from tablename where name='AAA' ---很想用pid=0,但你没有说明pid的概念。while exists (
select id from tablename a
where exists (select 1 from @Temp where id=a.pid)
and not exists (select 1 from @Temp where id=a.id)
)
insert @Temp
select id from tablename a
where exists (select 1 from @Temp where id=a.pid)
and not exists (select 1 from @Temp where id=a.id) select * from tablename a
where not exists (select 1 from @Temp where id=a.id)
按你的提示写出来速度一定不是最优的。declare @Temp table (id int)insert @Temp
select id from tablename where name='AAA' ---很想用pid=0,但你没有说明pid的概念。while exists (
select id from tablename a
where exists (select 1 from @Temp where id=a.pid)
and not exists (select 1 from @Temp where id=a.id)
)
insert @Temp
select id from tablename a
where exists (select 1 from @Temp where id=a.pid)
and not exists (select 1 from @Temp where id=a.id) select * from tablename a
where not exists (select 1 from @Temp where id=a.id)
解决方案 »
- 求SQL语句,根据条件删除其他重复的数据
- 如何判断同一列不同数据
- 多表查询 判断还增加个字段该怎么写这个查询语句
- 存储过程有没有以数组方式提供的参数?如果没有,怎么使用数量不固定的参数呢?
- 关于一个去掉重复记录的查询的问题 谢谢~~~~~~
- 我在dos下的.dbf文件坏了怎样修,谁能给我发一个foxbase+我的邮箱是:
- 求SQL语句,关于字符串连接的。有点难度。(即刻结分)
- 如何还原数据库?
- 在C++ Builder程序中怎么用语句创建SQL SERVER7.0的存储过程?
- 用VB开发数据库遇到书签的难题,请各位高手帮忙!
- 怎么将novell4.1下的数据库BTRIEVE转换成SQLSERVER里
- Sql Server 输入汉字乱码问题,急!!!!
where name<>'AAA'
and not exists (
select 1 from tablename b
where exists (
select 1 from tablename c
where name='AAA'
and id=b.pid
)
and a.PATH like '%>'+cast (b.id as varchar(8))+'>%'
)
where a.name<>'AAA' AND not exists
(select ID from tuser
where [user]=a.[user] and name='AAA' and patindex('%>'+convert(varchar(5),ID)+'>%',a.path)>1)
where a.name<>'AAA' AND not exists
(select ID from tuser
where name='AAA' and patindex('%>'+convert(varchar(5),ID) +'>%',a.path)>1)
也可以的.