select 名称 from a t 
where not exists(select 1 from a where 所属父目录的号=t.唯一号)

解决方案 »

  1.   

    select 名称 from a where 唯一号 not in(select distinct  所属父目录的号 from a)
      

  2.   

    declare @tb table
    (
       名称 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)
    */
      

  3.   

    必须要建个临时的tabel吗??