delete from tb
where id in (
select id
from tb A
where not exists(select 1 from tb B where A.menuYpte=parentid)
)

解决方案 »

  1.   

    select *
    from tb as t
    where exists(select 1 from tb where ParentID=T.ID)
      

  2.   

    delete
    from tb  
    where exists(select 1 from tb where ParentID=tb.ID)
      

  3.   

    ??SELECT *
    FROM TB T
    WHERE exists
    (
    SELECT 1 
    FROM TB 
    WHERE ID<>1 OR (ID=1 and ParentID=T.ID)
    )
      

  4.   

    SELECT *
    FROM TB T
    WHERE exists
    (
    SELECT 1 
    FROM TB 
    WHERE MenuType<>1 OR (MenuType=1 and ParentID=T.ID)
    )
      

  5.   

    DECLARE @TB TABLE(ID int,MenuType int,ParentID int)
    INSERT @TB
    SELECT 2,1,1 union all
    SELECT 3,2,2 union all
    SELECT 4,2,2 union all
    SELECT 5,1,1 union all
    SELECT 6,2,5 union all
    SELECT 7,2,5 union all
    SELECT 8,2,5 union all
    SELECT 10,1,1select *
    from @TB as t
    where MenuType<>1 or (MenuType=1 AND exists(select 1 from @TB where ParentID=T.ID))ID          MenuType    ParentID
    ----------- ----------- -----------
    2           1           1
    3           2           2
    4           2           2
    5           1           1
    6           2           5
    7           2           5
    8           2           5(7 行受影响)
      

  6.   

    图中的第8行数据(ID=10的那条) 
    我想将其过滤掉 
    他的特点是 
    MenuType=1  并且所有数据中没有一行的PrentID=10的 就是为主菜单(MenuType=1 ) 但是改主菜单下无子菜单的 过滤掉 
    谢谢帮助条件可对...