這句SQL語句沒有明顯的語法錯誤,但是邏輯可能存在問題。因為and運算符的優先級高於or運算符,所以這個SQL語句的實際邏輯是:

select distinct dept
from xx_equipment_info where (org_code='CH' and enabled='Y' and form_ver is null) or desc_1 is null order by dept,code

如果這正是您想要的邏輯,那麼這句SQL是沒有問題的。但是如果您的意圖是先匹配org_code、enabled和form_ver,然後再檢查desc_1,那麼您需要使用括號來明確優先級:

select distinct dept
from xx_equipment_info where org_code='CH' and enabled='Y' and (form_ver is null or desc_1 is null) order by dept,code

這樣的話,這句SQL的邏輯就是先匹配org_code、enabled和form_ver,然後再檢查desc_1

請判定這句sql是否有問題這是oracle數據庫。select distinct dept from xx_equipment_info where org_code=CH and enabled=Y and form_ver is null or desc_1 is null order by deptcode

原文地址: https://www.cveoy.top/t/topic/fi1n 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录