如何用一个sql语句来实现这个表的查询,并的出结果?? select 名称 from a t where not exists(select 1 from a where 所属父目录的号=t.唯一号) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select 名称 from a where 唯一号 not in(select distinct 所属父目录的号 from a) declare @tb table( 名称 varchar(10), 判断目录层次 int, 所属父目录的号 int, 唯一号 int)insert @tbselect '亚洲', 0, 0, 1 unionselect '欧洲', 0, 0, 2 unionselect '中国', 1, 1, 3 unionselect '朝鲜', 1, 1, 4 unionselect '伊朗', 1, 1, 5 unionselect '广东', 2, 3, 6 unionselect '北京', 2, 3 , 7--查询 select 名称 from @tb t where not exists(select 1 from @tb where 所属父目录的号=t.唯一号) --结果/*名称 ---------- 北京朝鲜广东欧洲伊朗(5 row(s) affected)*/ 必须要建个临时的tabel吗?? 取每个人的最高分,只有100分,望大大解决 数据导入 游标@@CURSOR_ROWS的问题 SQL查询问题,在线等(急) 出现备份集 查询分析问题 截获程序发出sql语句 如何批量提取存储过程的原代码,并存储为SQL语句 怎样计算回头次数? 急急!!错将数据库的一个表中的许多记录删除掉了,怎么恢复?没有备份过数据库. 怎样列出所有作业? MSSQL自动编号问题原来这样可以搞定!
(
名称 varchar(10),
判断目录层次 int,
所属父目录的号 int,
唯一号 int
)
insert @tb
select '亚洲', 0, 0, 1 union
select '欧洲', 0, 0, 2 union
select '中国', 1, 1, 3 union
select '朝鲜', 1, 1, 4 union
select '伊朗', 1, 1, 5 union
select '广东', 2, 3, 6 union
select '北京', 2, 3 , 7--查询
select 名称 from @tb t
where not exists(select 1 from @tb where 所属父目录的号=t.唯一号)
--结果
/*
名称
----------
北京
朝鲜
广东
欧洲
伊朗(5 row(s) affected)
*/