2017-05-17 12 views
0

私はBigQueryコンソールで作業していますが、12種類のデータセットから共用体を作成する必要がありますが、情報は同じです。データ範囲はすべて同じですので、dataset_idを変更してください。UNION ALLまたはCONCATENATE BigQueryのデータセット

私はunion allファンクションを最初のクエリの最後に配置し、次の他のクエリを配置しようとしますが、機能しません。

Error: SELECT list expression references hits.contentgroup.contentgroup2 which is neither grouped nor aggregated at [2:3] 

これはクエリです:

SELECT 
    hits.contentgroup.contentgroup2 CampaignGrouping, 
    custd.value member_PK, 
    'Web' Canal, 
    'ES' AS country_id, 
    SUM(hits.contentGroup.contentGroupUniqueViews2) VistasUnicas 
FROM 
    `id_project.11773102.ga_sessions*`, 
    UNNEST(customdimensions) custd, 
    UNNEST(hits) AS hits 
WHERE 
    1 = 1 
    AND PARSE_TIMESTAMP('%Y%m%d', REGEXP_EXTRACT(_table_suffix, r'.*_(.*)')) BETWEEN TIMESTAMP('2017-04-25') AND TIMESTAMP('2017-04-30') 
    AND custd.index=30 
    and hits.contentGroup.contentGroup2 <> '(not set)' 
    AND custd.value <> 'null' 
    AND hits.contentGroup.contentGroupUniqueViews2 IS NOT NULL 
UNION ALL 
SELECT 
    hits.contentgroup.contentgroup2 CampaignGrouping, 
    custd.value member_PK, 
    'Web' Canal, 
    'ES' AS country_id, 
    SUM(hits.contentGroup.contentGroupUniqueViews2) VistasUnicas 
FROM 
    `id_project.11773102.ga_sessions*`, 
    UNNEST(customdimensions) custd, 
    UNNEST(hits) AS hits 
WHERE 
    1 = 1 
    AND PARSE_TIMESTAMP('%Y%m%d', REGEXP_EXTRACT(_table_suffix, r'.*_(.*)')) BETWEEN TIMESTAMP('2017-04-25') AND TIMESTAMP('2017-04-30') 
    AND custd.index=30 
    and hits.contentGroup.contentGroup2 <> '(not set)' 
    AND custd.value <> 'null' 
    AND hits.contentGroup.contentGroupUniqueViews2 IS NOT NULL 
GROUP BY 
    1, 2 
ORDER BY 5 ASC 

感謝。あなたは労働組合の最初のクエリでGROUP BYを使用する必要が

+1

あなたが何を、もしあれば、エラーを取得しています。 "うまくいかない"ことを説明する - IOW、うまくいかない。 –

+0

申し訳ありません@SloanThrasher私は今質問に含まれています –

+0

したがって、エラーメッセージはかなり明確に思われる。 hits.contentgroup.contentgroup2はどこから来たのですか? –

答えて

1

、例えば:

SELECT 
    hits.contentgroup.contentgroup2 CampaignGrouping, 
    custd.value member_PK, 
    'Web' Canal, 
    'ES' AS country_id, 
    SUM(hits.contentGroup.contentGroupUniqueViews2) VistasUnicas 
FROM 
    `bigquery-aaaaa-162814.11773102.ga_sessions*`, 
    UNNEST(customdimensions) custd, 
    UNNEST(hits) AS hits 
WHERE 
    1 = 1 
    AND PARSE_TIMESTAMP('%Y%m%d', REGEXP_EXTRACT(_table_suffix, r'.*_(.*)')) BETWEEN TIMESTAMP('2017-04-25') AND TIMESTAMP('2017-04-30') 
    AND custd.index=30 
    and hits.contentGroup.contentGroup2 <> '(not set)' 
    AND custd.value <> 'null' 
    AND hits.contentGroup.contentGroupUniqueViews2 IS NOT NULL 
GROUP BY 1, 2 
UNION ALL 
SELECT ... 

GROUP BYUNION ALLの具体的な例として:

#standardSQL 
WITH T AS (
    SELECT 1 AS x, 'foo' AS y UNION ALL 
    SELECT 1, 'bar' UNION ALL 
    SELECT 2, 'foo' 
) 
SELECT x, STRING_AGG(y, ',') AS y 
FROM T 
GROUP BY x 
UNION ALL 
SELECT SUM(x), y 
FROM T 
GROUP BY y; 
+0

RUN !!!ありがとう、最初のコードが正常に実行されます! :D –

関連する問題