0

我将此查询与虚拟列一起使用New_Users

SELECT `r`.`deal_id` as Deal_ID, 
       concat("2013\-05\-15") as start_date, 
       concat("2013\-05\-16") as end_date, 
       abs(0) AS New_Members 
  FROM (`ws_deal` r) 
 WHERE New_Members != 0 
 ORDER BY `deal_id`" 

我在 'where 子句' SQL.sql 1 118 中有一个错误“1 Unknown column 'New_Members'”

如果我没有使用New_Members != 0并且如果查询是

 SELECT `r`.`deal_id` as Deal_ID, 
        concat("2013\-05\-15") as start_date, 
        concat("2013\-05\-16") as end_date, 
        abs(0) AS New_Members 
   FROM (`ws_deal` r)  
  ORDER BY `deal_id` 
  LIMIT 12"  

我得到一个结果。

Deal_ID start_date      end_date       New_Members  

407 2013-05-15  2013-05-16  0
408 2013-05-15  2013-05-16  0
409 2013-05-15  2013-05-16  0
410 2013-05-15  2013-05-16  0
411 2013-05-15  2013-05-16  0
412 2013-05-15  2013-05-16  0
413 2013-05-15  2013-05-16  0
414 2013-05-15  2013-05-16  0
415 2013-05-15  2013-05-16  0
416 2013-05-15  2013-05-16  0
417 2013-05-15  2013-05-16  0

我的问题是为什么我不能过滤这个结果。我怎样才能过滤这个。(无论如何New_Member != 0,您可能会认为不需要过滤器。但是我需要通过过滤器来实现这一点,而这是在大查询集中动态生成的查询)

非常感谢

4

2 回答 2

0

首先, abs(0) 没有意义。它总是返回 0。

其次,您不能在 where 子句中使用别名。您必须在查询中进行查询。

于 2013-09-22T09:00:59.267 回答
0

您不能在 where 子句中使用别名列,但可以使用子查询并按新列过滤:

select
    Deal_ID, start_date, end_date, New_Members
from (
    select
        `r`.`deal_id` as Deal_ID, 
        concat("2013\-05\-15") as start_date, 
        concat("2013\-05\-16") as end_date, 
        abs(0) AS New_Members 
    from (`ws_deal` r) 
) as a
where New_Members != 0 
order by `deal_id`" 
于 2013-09-22T08:57:55.853 回答