配置单元中的模糊列引用

时间:2017-09-12 18:28:32

标签: hive

我想找到"秒"的平均值。从下面的查询。我在t"。

中得到错误"不明确的列引用date_time

我不确定如何解决它。任何建议都会很棒!!

 select dayname(tc.date_time), sum(seconds) from (
  select td.visid, td.visid1, td.num, concat(td.visid, td.visid1, td.num) as session,td.date_time, tc.date_time,
  second(tc.date_time) - second(td.date_time) as seconds
  from tb1 as td 
  join tb2 as tc
  on td.visid = tc.visid and  td.visid1 = tc.visid1 and td.num = tc.num and
  td.name = 'Detail' and tc.name = 'Confirm'
  where td.date_time between "2017-05-01 00:00:00" and "2017-07-31 00:00:00") as t
  group by dayname(tc.date_time);

1 个答案:

答案 0 :(得分:0)

两个表中的相同列名date_time都会产生问题。为这两列提供别名。这将解决您的问题。

   select dayname(t.a), sum(t.seconds) from (
  select td.visid, td.visid1, td.num, concat(td.visid, td.visid1, td.num) as session,td.date_time as d, tc.date_time as a,
  second(tc.date_time) - second(td.date_time) as seconds
  from tb1 as td 
  join tb2 as tc
  on td.visid = tc.visid and  td.visid1 = tc.visid1 and td.num = tc.num and
  td.name = 'Detail' and tc.name = 'Confirm'
  where td.date_time between "2017-05-01 00:00:00" and "2017-07-31 00:00:00") as t
  group by dayname(t.a);