SQL if判断
SELECT Menu_Id, IF EXISTS(SELECT Menu_Id FROM cy_bt_Menu_Unit WHERE (Menu_Id = 'Menu_Id')) '存在' ELSE '不存在' AS d
FROM cy_bt_Menu_Info
判断 复制D
这个语句怎么不对啊!
------最佳解决方案--------------------SELECT Menu_Id, case when EXISTS(SELECT 1 FROM cy_bt_Menu_Unit WHERE Menu_Id = a.Menu_Id) then '存在' ELSE '不存在' end AS d
FROM cy_bt_Menu_Info as a
------其他解决方案--------------------SELECT Menu_Id, CASE (SELECT COUNT(Menu_Id) FROM cy_bt_Menu_Unit WHERE (Menu_Id = 'Menu_Id')) WHEN 0 THEN '存在' ELSE '不存在' END AS d
FROM cy_bt_Menu_Info
------其他解决方案--------------------要用case when
SELECT Menu_Id ,
CASE WHEN b.Menu_Id IS NOT NULL THEN '存在'
ELSE '不存在'
END d
FROM cy_bt_Menu_Info a
LEFT JOIN ( SELECT Menu_Id
FROM cy_bt_Menu_Unit
WHERE ( Menu_Id = 'Menu_Id' )
) b ON a.menu_id = b.menu_id
------其他解决方案--------------------SELECT a.Menu_Id ,
CASE WHEN b.Menu_Id IS NULL THEN '不存在'
ELSE '存在'
END AS d
FROM cy_bt_Menu_Info a
LEFT JOIN ( SELECT Menu_Id
FROM cy_bt_Menu_Unit
WHERE ( Menu_Id = 'Menu_Id' )
) b ON a.Menu_Id = b.Menu_Id
------其他解决方案--------------------要用case when EXISTS(SELECT 1 FROM cy_bt_Menu_Unit WHERE Menu_Id = a.Menu_Id) then '存在' ELSE '不存在' end
if else是不合法的