我有这个查询..
SELECT DATE_FORMAT(utcdt,GET_FORMAT(DATE,'ISO')) as utcdt,
HOUR(utcdt) as hour,
country,
sum(impressions) as impressions
FROM rtb_impressions where campaign_id='cid2204184260'
GROUP BY utcdt, hour, country
这些是结果.....
{'impressions': Decimal('1'), 'country': 'US', 'hour': 10L, 'utcdt': '2012-10-01'}
{'impressions': Decimal('40000'), 'country': 'US', 'hour': 9L, 'utcdt': '2012-10-02'}
{'impressions': Decimal('20000'), 'country': 'US', 'hour': 9L, 'utcdt': '2012-10-02'}
为什么我本应该得到2行却得到3行? 012-10-02应该已经汇总。
谢谢
最佳答案
之所以会得到它,是因为您按错误的值进行分组。
尝试以下方法:
SELECT DATE_FORMAT(utcdt,GET_FORMAT(DATE,'ISO')) as utcdt,
HOUR(utcdt) as hour,
country,
sum(impressions) as impressions
FROM rtb_impressions where campaign_id='cid2204184260'
GROUP BY DATE_FORMAT(utcdt,GET_FORMAT(DATE,'ISO')), hour, country