How to use Hive Query results(multiple) in a variable for other query

后端 未结 1 1528
情歌与酒
情歌与酒 2021-01-07 04:15

I have two tables one is schools and one is students.I want to find all the students of a particular school. The schema of schools is: id, name, location and of students is

1条回答
  •  花落未央
    2021-01-07 05:16

    Use collect_set() with concat_ws to get comma delimited string, IDs should be cast to string:

    schoolId=$(hive -e "set hive.cli.print.header=false;select concat_ws('\\',\\'',collect_set(cast(id as string))) from school;");
    
    hive -hiveconf "schoolId"="$schoolId" 
    

    Then use IN operator:

    select id,name from student where schoolId in ('${hiveconf:schoolId}');
    

    0 讨论(0)
提交回复
热议问题