1
SELECT ymd, 
       creative_id, 
       sum(imps) as imps, 
       sum(booked_revenue_dollars) as booked_rev
  FROM agg_dw_advertiser_publisher_analytics_adjusted
 WHERE buyer_member_id=456
   AND (sum(imps) > 500 WHERE ymd > current_date() - 14) #this part is wrong
 GROUP BY 1,2
HAVING min(ymd) < current_date() - 14
 ORDER BY 2,1 ASC;

ymd = 年/月/日

我试图过滤掉过去 2 周内creative_id字段总和imps小于 500 的 's 。我显然做的不对,但我尝试过作为附加HAVING子句和子查询。我究竟做错了什么?

4

2 回答 2

0

没有这样的概念称为嵌套 WHERE。你可以HAVING像这样修改你的。

SELECT creative_id, 
       sum(imps) as imps, 
       sum(booked_revenue_dollars) as booked_rev
  FROM agg_dw_advertiser_publisher_analytics_adjusted
 WHERE buyer_member_id=456
 GROUP BY creative_id
HAVING sum(imps) > 500 AND min(ymd) > current_date() - 14
 ORDER BY 2,1 ASC;
于 2013-04-12T21:12:34.670 回答
0

像这样的东西(我的头顶)

SELECT ymd, creative_id, 
       sq.imps as imps,
       sq.booked_rev as booked_rev
  FROM agg_dw_advertiser_publisher_analytics_adjusted a
  INNER JOIN 
      (
       SELECT creative_id, sum(imps) as imps, sum(booked_revenue_dollars) as booked_rev
       FROM agg_dw_advertiser_publisher_analytics_adjusted
       WHERE buyer_member_id=456 and ymd > current_date() - 14
       GROUP BY creative_id
      ) as sq
    ON  a.creative_id = sq.creative_id
 WHERE buyer_member_id=456 and sq.imps > 500 and ymd > current_date() - 14
 ORDER BY ymd,creative_id ASC;
于 2013-04-12T21:34:06.917 回答