Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the google-analytics-for-wordpress domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/nantonaku/www/wp-ntnk/wp-includes/functions.php on line 6121
Cousera クエリエラー - nantonaku

Cousera クエリエラー

現在、couseraの「Google データアナリティクス プロフェッショナル認定証」を実践している。
その中で、度々クエリのエラーが出ているので、備忘録としてメモしておく。

5 .データを分析し、答えを導き出す > モジュール4 > 実践編:一時テーブルを作成する

記載内容通りにクエリを入力、実行するとエラーが出る。

実行クエリ

WITH longest_used_bike AS (
  SELECT
    bike_id,
    SUM(duration_minutes) AS trip_duration
  FROM
    bigquery-public-data.austin_bikeshare.bikeshare_trips
  GROUP BY
    bike_id
  ORDER BY
    trip_duration DESC
  LIMIT 1 
)

## 最長距離移動した自転車の出発地点を調べる 
SELECT
  trips.start_station_id,
  COUNT(*) AS trip_ct
FROM
  longest_used_bike AS longest
INNER JOIN
  bigquery-public-data.austin_bikeshare.bikeshare_trips 
ON longest.bike_id = trips.bike_id
GROUP BY
  start_station_id
ORDER BY
  trip_ct DESC
LIMIT 1

エラー

Unrecognized name: trips; Did you mean trip_id? at [22:22]

確認したところ、以下のようである。

エラーの原因は、trips がクエリ内で定義されていないためです。この名前を使っている箇所では正しいテーブルエイリアスが必要です。

ということで、修正したコードは以下。

WITH longest_used_bike AS (
  SELECT
    bike_id,
    SUM(duration_minutes) AS trip_duration
  FROM
    bigquery-public-data.austin_bikeshare.bikeshare_trips
  GROUP BY
    bike_id
  ORDER BY
    trip_duration DESC
  LIMIT 1
)

## 最長距離移動した自転車の出発地点を調べる 
SELECT
  trips.start_station_id,
  COUNT(*) AS trip_ct
FROM
  longest_used_bike AS longest
INNER JOIN
  `bigquery-public-data.austin_bikeshare.bikeshare_trips` AS trips
ON longest.bike_id = trips.bike_id
GROUP BY
  trips.start_station_id
ORDER BY
  trip_ct DESC
LIMIT 1;

これで、エラーがなく正しい値が返ってきたので、解決。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です