有人可以幫助我處理此查詢嗎?使用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