有人可以帮助我处理此查询吗?使用CASE作为可选谓词
我是使用CASE的新手,我该如何做这项工作。如果权限=经理,那么我想在案件中运行代码。
select email, user_id, first_name, last_name, rights
from users u
where company_id = 2141
and receives_emails = 'y'
case u.rights when 'manager' then
and user_id in (select user_id from manager_depts where company_id = u.company_id and dept_id = 2)
end
谢谢!
您正在使用什么RDBMS? – Dan 2012-02-16 22:51:45
您是否试图查看用户是经理,还是只想回到他们,如果他们是经理?这不是一种命令式语言 - 你不能(通常)从'WHERE'子句中修改一个表。 – 2012-02-16 22:52:07