日期:2014-05-18  浏览次数:20426 次

父子表
父子表中级别问题
怎么计算它们的级别啊?
有什么函数可以做到吗?

------解决方案--------------------
最好是在前台程序或触发器里实现.

如果以前没有维护级别,可通过某一子类查它父类有多少级来计算.
------解决方案--------------------
if exists(select 1 from 表 where 列1 in (select 列2 from 表))
print '存在 '
else
print '不存在 '
------解决方案--------------------
SQL SERVER 2000还上2005里的?
------解决方案--------------------
select * from t1 where t1.id not in (select id from t2)
------解决方案--------------------
create table #t1(col1 varchar(10))
insert into #t1
select '01 '
union select '02 '
union select '03 '
union select '05 '

create table #t2(col1 varchar(10))
insert into #t2
select '01 '
union all select '02 '
union all select '03 '
union all select '04 '
union all select '05 '

select * from #t2
where not exists(select 1 from #t1 where #t1.col1=#t2.col1)
--结果
/*
col1
----------
04
(所影响的行数为 1 行)
*/
------解决方案--------------------
xiangshuiyoudu() ( ) 信誉:100 Blog 加为好友 2007-04-17 14:18:06 得分: 0


select 语句里面可以加循环吗?

-------------------------------------
不明白什么意思.
循环可以用
while <条件>
begin
...
end