select * from tb as t where exists(select 1 from tb where ParentID=T.ID)
delete from tb where exists(select 1 from tb where ParentID=tb.ID)
??SELECT * FROM TB T WHERE exists ( SELECT 1 FROM TB WHERE ID<>1 OR (ID=1 and ParentID=T.ID) )
SELECT * FROM TB T WHERE exists ( SELECT 1 FROM TB WHERE MenuType<>1 OR (MenuType=1 and ParentID=T.ID) )
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 行受影响)
from tb as t
where exists(select 1 from tb where ParentID=T.ID)
from tb
where exists(select 1 from tb where ParentID=tb.ID)
FROM TB T
WHERE exists
(
SELECT 1
FROM TB
WHERE ID<>1 OR (ID=1 and ParentID=T.ID)
)
FROM TB T
WHERE exists
(
SELECT 1
FROM TB
WHERE MenuType<>1 OR (MenuType=1 and ParentID=T.ID)
)
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 行受影响)
我想将其过滤掉
他的特点是
MenuType=1 并且所有数据中没有一行的PrentID=10的 就是为主菜单(MenuType=1 ) 但是改主菜单下无子菜单的 过滤掉
谢谢帮助条件可对...