2017-08-09 9 views
0

Ich muss Werte aus 2 Tabellen in eine Tabelle einfügen. In dieser Tabelle muss ich IDs für beide primäre und andere Medikamente zuweisen, die in einer Spalte in einer anderen Tabelle sind. So alle Spalten werden aus einer Tabelle (d_temp_drugs) und nur IDs von primären und anderen Drogen aus anderem Tisch kommen (unique_drugs_drug_id)Fehler beim Einfügen von Werten in die Hive-Tabelle

verwende ich für diese kommen und immer Fehler „Fehler bei Anweisung Kompilieren: failed: SemanticException [Fehler 10007]: Mehrdeutige Spaltenreferenz drug_id in _u1-subquery1 "

Unten ist der Code, den ich verwende, um Tabellen zu erstellen und Werte einzufügen. Bitte schlagen Sie eine Lösung vor.

create table study_drug_mapping 
(
    trial_identifier string, 
    cto_id int, 
    primary_drug string, 
    primary_drug_id int, 
    other_drug string, 
    other_drug_id int 
) 

insert into table study_drug_mapping (trial_identifier, cto_id, primary_drug, primary_drug_id, other_drug, other_drug_id) 
select d_temp_drugs.trial_identifier, d_temp_drugs.cto_id, d_temp_drugs.primary_drugs_sorted, unique_drugs_drug_id.drug_id, d_temp_drugs.other_drugs_sorted, unique_drugs_drug_id.drug_id 
from 
(
select d_temp_drugs.trial_identifier, d_temp_drugs.cto_id, d_temp_drugs.primary_drugs_sorted, drugs.drug_id, d_temp_drugs.other_drugs_sorted, drugs.drug_id 
from d_temp_drugs left join unique_drugs_drug_id drugs on d_temp_drugs.primary_drugs_sorted = drugs.unique_drug_name 
union 
select d_temp_drugs.trial_identifier, d_temp_drugs.cto_id, d_temp_drugs.primary_drugs_sorted, drugs.drug_id, d_temp_drugs.other_drugs_sorted, drugs.drug_id 
from d_temp_drugs left join unique_drugs_drug_id drugs on d_temp_drugs.other_drugs_sorted = unique_drugs_drug_id.unique_drug_name 
) a 

Antwort

0

try this:

create table study_drug_mapping 
(
    trial_identifier string, 
    cto_id int, 
    primary_drug string, 
    primary_drug_id int, 
    other_drug string, 
    other_drug_id int 
); 

insert into table study_drug_mapping 
select 
    trial_identifier, 
    cto_id, 
    primary_drugs_sorted, 
    drug_id, 
    other_drugs_sorted, 
    drug_id 
from 
(
select 
    d_temp_drugs.trial_identifier as trial_identifier, 
    d_temp_drugs.cto_id as cto_id, 
    d_temp_drugs.primary_drugs_sorted as primary_drugs_sorted, 
    drugs.drug_id as drug_id, 
    d_temp_drugs.other_drugs_sorted as other_drugs_sorted, 
    drugs.drug_id as drug_id 
from d_temp_drugs left join unique_drugs_drug_id drugs on (d_temp_drugs.primary_drugs_sorted = drugs.unique_drug_name) 
union 
select 
    d_temp_drugs.trial_identifier as trial_identifier, 
    d_temp_drugs.cto_id as cto_id, 
    d_temp_drugs.primary_drugs_sorted as primary_drugs_sorted, 
    drugs.drug_id as drug_id, 
    d_temp_drugs.other_drugs_sorted as other_drugs_sorted, 
    drugs.drug_id as drug_id 
from d_temp_drugs left join unique_drugs_drug_id drugs on (d_temp_drugs.other_drugs_sorted = unique_drugs_drug_id.unique_drug_name) 
)a 
+0

diesen Fehler : Fehler beim Kompilieren der Anweisung: FAILED: ParseException Zeile 11: 0 fehlendes EOF bei 'Einfügen' in der Nähe ')' – Vaibhav

+0

Ich sehe ... habe vergessen hinzuzufügen ";" Nach dem Erstellen der Tabelle sollte es jetzt OK sein – Jenny

0

Bitte geben diesem einen Versuch, Sie sind ziemlich nah verweisen Sie die SUBQUERY Tabelle in der letzten SELECT, die den Fehler wirft

INSERT INTO TABLE study_drug_mapping (trial_identifier, cto_id, primary_drug, primary_drug_id, other_drug, other_drug_id) 
SELECT 
     A.trial_identifier, 
     A.cto_id, 
     A.primary_drugs_sorted, 
     A.drug_id, 
     A.other_drugs_sorted, 
     A.drug_id 
FROM 
(
SELECT 
     d_temp_drugs.trial_identifier, 
     d_temp_drugs.cto_id, 
     d_temp_drugs.primary_drugs_sorted, 
     drugs.drug_id, 
     d_temp_drugs.other_drugs_sorted, 
     drugs.drug_id 
FROM d_temp_drugs 
LEFT JOIN unique_drugs_drug_id drugs ON d_temp_drugs.primary_drugs_sorted = drugs.unique_drug_name 
UNION --Make use of UNION ALL incase you need all the data from both the SELECT statements 
SELECT 
     d_temp_drugs.trial_identifier, 
     d_temp_drugs.cto_id, 
     d_temp_drugs.primary_drugs_sorted, 
     drugs.drug_id, 
     d_temp_drugs.other_drugs_sorted, 
     drugs.drug_id 
FROM d_temp_drugs 
LEFT JOIN unique_drugs_drug_id drugs ON d_temp_drugs.other_drugs_sorted = unique_drugs_drug_id.unique_drug_name 
) A 
Verwandte Themen