【发布时间】:2014-07-08 21:45:27
【问题描述】:
我需要一个执行如下操作的 sql:
SELECT col1, col2, cond4 as cond4_is_exclusive
FROM table
WHERE (cond1 AND cond2 AND cond3) OR cond4
其中 cond4 = (col3 IN (...))
我需要 cond4_is_exclusive 为 TRUE,前提是 cond4 本身满足条件,而不是 cond1 和 cond2 和 cond3,因为它们之间存在 OR。
有这样的解决方案吗?
我需要一个优雅和优化的解决方案,因为查询更大,条件更多,更复杂。
我现在的工作是这样的:
SELECT col1, col2, (cond1 AND cond2 AND cond3) as c1, cond4 c2
FROM table
WHERE (cond1 AND cond2 AND cond3) OR cond4
后来c2和c2用php检查,不是那么优雅
【问题讨论】:
标签: mysql sql postgresql