1
(SELECT
id,
SUM(hits/ab) AS HAB
FROM batting
GROUP BY id
) b
SELECT id, bmonth, bstate FROM master a
WHERE bmonth >= 0 AND bstate is NOT NULL
GROUP By bmonth,bstate
到目前爲止,我有這個亂碼,但我迷失在如何形成連接,然後繼續。我不知道從哪裏開始儘可能地做事。我們應該加入還是使用子查詢?請協助下面的架構Hive加入或子查詢混淆
看:
CREATE EXTERNAL TABLE IF NOT EXISTS batting
(id STRING, year INT, team STRING,
league STRING, games INT, ab INT, runs INT, hits INT, doubles INT, triples INT,
homeruns INT, rbi INT, sb INT, cs INT, walks INT, strikeouts INT, ibb INT,
hbp INT, sh INT, sf INT, gidp INT)
ROW FORMAT DELIMITED FIELDS
TERMINATED BY ',' LOCATION '/home/hduser/hivetest/batting';
CREATE EXTERNAL TABLE IF NOT EXISTS master
(id STRING, byear INT, bmonth INT, bday INT, bcountry STRING, bstate STRING,
bcity STRING, dyear INT, dmonth INT, dday INT, dcountry STRING, dstate STRING,
dcity STRING, fname STRING, lname STRING, name STRING, weight INT, height INT,
bats STRING, throws STRING, debut STRING, finalgame STRING, retro STRING,
bbref STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/home/hduser/hivetest/master';
喜感謝u爲答案,但得到一個無法識別輸入「(」「(」從源「選擇」失敗:ParseException的 – dedpo
@dedpo我已經編輯了答案,儘量不要now.Sorry無法訪問羣集 –
這不是預期的輸出,但它對於如何執行多連接非常有用 – dedpo