gpt4 book ai didi

hiveQL if 语句在一行上重新组合

转载 作者:行者123 更新时间:2023-12-05 01:08:39 27 4
gpt4 key购买 nike

查询:

select IF(type='view', count(*), 0), IF(type='click', count(*), 0)
from ad_events
where year=2013 and month=01 and day=18 and (hour=01 or hour=02)
group by type

结果:

      _c0       _c1
0 0 0
1 0 0
2 0 1368
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 277917 0
9 0 0

有没有像这样只在一行中得到结果的方法? :

      _c0       _c1
0 277917 1368

最佳答案

好的,我只是在嵌套查询中这样做了:

select SUM(c), SUM(v)
from (
select tracking_id, IF(type='view', count(*), 0) AS v, IF(type='click', count(*), 0) AS c
from ad_events
where year=2013 and month=01 and day=18
group by tracking_id, type
) t2

关于hiveQL if 语句在一行上重新组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14532908/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com