2

selectHive でさまざまな条件でネストできますか? 例えば

次の 2 つの Hive クエリがあるとします。

select percentile(x, 0.95)
from t1
where y = 1;

select percentile(x, 0.95)
from t1
where y = 2;

上記の 2 つのパーセンタイルを 1 つのクエリで選択できますか? (うまくいきません):

select
  (select percentile(x, 0.95)
    from t1
    where y = 1),
  (select percentile(x, 0.95)
    from t1
    where y = 2)
from t1;
4

3 に答える 3

3

UNION ALLたとえば、 を使用してこれを行うことができます。

select * from
  (select percentile(x, 0.95)
    from t1
    where y = 1
   union all
   select percentile(x, 0.95)
    from t1
    where y = 2) x;
于 2013-01-25T01:35:08.027 に答える
0

試すこともできます:

select percentile( case when y=1 then x else null end, 0.95) as p95_1
     , percentile( case when y=2 then x else null end, 0.95) as p95_2
from table;

percentile() は null 値を無視します。

于 2015-06-25T20:24:49.200 に答える