0

我有这个查询:

SELECT Param1, Param2 AS P1
FROM SomeTable

我想做这样的事情:

WHERE P1 > 2

有办法做到这一点吗?当然有一个查询而不是Param2。

4

7 回答 7

2
WITH ABC
AS
(
SELECT Param1, Param2 AS P1
FROM SomeTable
)
SELECT * from ABC where P1>2
于 2012-12-26T06:16:23.970 回答
0

您可以使用having

尝试这个

select param1,param2 as p1
 from table
 having p1 > 2
于 2012-12-26T06:15:38.677 回答
0

而不是 where 使用有子句..

    SELECT Param1, Param2 AS P1 
     FROM SomeTable 
     having P1>2;
于 2012-12-26T06:16:18.097 回答
0

尝试这个,

SELECT Param1, 
[P1] = Param2
FROM SomeTable
WHERE [P1] > 2

如果您使用的是 ms sql 这应该可以

于 2012-12-26T06:36:40.560 回答
0

您可以使用子查询:

SELECT Param1, P1
FROM
(
  SELECT Param1, Param2 AS P1
  FROM SomeTable
) src
WHERE P1 > 2
于 2012-12-26T06:17:00.577 回答
0

阅读此内容以获取详细说明:

http://databases.aspfaq.com/database/how-do-i-use-a-select-list-alias-in-the-where-or-group-by-clause.html

拉吉

于 2012-12-26T06:34:03.600 回答
0

HAVING行不通。上面提到的通用表是一个很好的方法。

于 2012-12-26T10:02:49.687 回答