I have a menu table and I am struggling to select all parent-menus without a child.
SELECT
CASE
WHEN (SELECT COUNT(1) children
FROM menu
WHERE cod_idiom = 'EN'
START WITH cod_menu_parent = m1.cod_menu
CONNECT BY PRIOR cod_menu = cod_menu_parent ) = 0 THEN
cod_menu
END x
FROM menu m1
WHERE m1.isSubMenu = 'T'
*isSubMen开发者_如何学运维u = 'T' means it might (should) have children which may be a sub-menu or a file.
The idea was to first query all sub-menus, get their menu code and then do a CONNECT BY PRIOR to count its children.
The above query didn't have the expected effect, do you guys have any idea?
SELECT m1.cod_menu
FROM menu m1
WHERE NOT EXISTS(SELECT NULL
FROM MENU m2
WHERE m1.cod_menu = m2.cod_menu_parent)
AND m1.isSubMenu = 'T'
精彩评论