3

クエリ:

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

そのような1行だけで結果を得る方法はありますか? :

      _c0       _c1
0    277917     1368
4

2 に答える 2

5

わかりました、ネストされたクエリでそれを行いました:

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
于 2013-01-29T00:28:48.450 に答える
2

フォローしてみてください

select
   type,
   count(type) TypeCount
from ad_events
where
   year=2013 and 
   month=01 and 
   day=18 and 
   (hour=01 or 
    hour=02)
group by type
于 2014-02-06T08:35:54.587 に答える