1

I was wondering if there is way to store where clause conditions and not calculate them more than once in order to determine which one was satisfied. Here is what I am talking about: select col, col1>5 cond1, col2<400 cond2 from table where col1>5 or col2<400

4

1 回答 1

3

我认为您不必担心为每一行col1 > 5计算多次简单的比较,但是为了节省输入更复杂的查询,您可以这样做:

SELECT col, col1 > 5 AS cond1, col2 < 400 AS cond2
FROM table
HAVING cond1 or cond2

使用having而不是可以访问子句where中引入的别名。select

于 2013-03-07T20:51:41.607 回答