Hive 获取此异常:失败:SemanticException[错误10025]:行5:45表达式不在GROUP BY key'&引用&引用';

Hive 获取此异常:失败:SemanticException[错误10025]:行5:45表达式不在GROUP BY key'&引用&引用';,hive,Hive,获取此异常:失败:SemanticException[错误10025]:尝试执行下面的配置单元查询时,第5:45行表达式不在GROUP BY key''''中。查询中有什么错误? Create table Daily_Summary_Table AS select Dt,Day_Of_Week,Mon, Yr,Weekend, Total_Trip_Count,Total_Trip_Fare,Total_Trip_Miles,Total_Trip_Duration, sum(mult_fare)

获取此异常:失败:SemanticException[错误10025]:尝试执行下面的配置单元查询时,第5:45行表达式不在GROUP BY key''''中。查询中有什么错误?

Create table Daily_Summary_Table AS
select Dt,Day_Of_Week,Mon, Yr,Weekend, Total_Trip_Count,Total_Trip_Fare,Total_Trip_Miles,Total_Trip_Duration,
sum(mult_fare)/count(*) as avg_wt_trip_fare,sum(mult_miles)/count(*) as avg_wt_trip_miles, sum(mult_dur) /count(*) as avg_wt_trip_dur
from
(select to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd')) as Dt,
from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'u') as Day_Of_Week,
from_unixtime(to_unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'MMM') as Mon,
year(to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd'))) as Yr,
Weekend, 
count(*) as Total_Trip_Count,
count(round(trip_fare)), as Total_Trip_Fare,
count(round(trip_miles)) as Total_Trip_Miles,
count(round(trip_seconds/60)) as Total_Trip_Duration,
count(taxi_id_int)*round(trip_fare) mult_fare, 
count(taxi_id_int)*round(trip_miles) mult_miles, 
count(taxi_id_int)*round(trip_seconds/60) mult_dur
from chicago_taxis.taxi_trip_details_weekend_encoded_sharmi) T
group by to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd')),
from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'u'),
from_unixtime(to_unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'MMM'),
year(to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd'))) ,
Weekend, 
round(trip_fare), 
round(trip_miles), 
round(trip_seconds/60);

因此,使用以下查询解决了该问题:

CREATE TABLE IF NOT EXISTS Daily_Summary_Table
STORED AS ORC 
AS
Select Date,
Day_Of_Week,
Month,
Year,
Weekend,
sum(mult_fare)/count(*) as avg_wt_trip_fare,sum(mult_miles)/count(*) as avg_wt_trip_miles, sum(mult_dur) /count(*) as avg_wt_trip_dur
from(
select to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd')) Date,
from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'u') Day_Of_Week,
from_unixtime(to_unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'MMM') Month,
year(to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd'))) Year,
Weekend, 
count(trip_id_int),
count(round(trip_fare)),
count(round(trip_miles)),
count(round(trip_seconds/60)),
count(taxi_id_int)*round(trip_fare) mult_fare, 
count(taxi_id_int)*round(trip_miles) mult_miles, 
count(taxi_id_int)*round(trip_seconds/60) mult_dur
from chicago_taxis.taxi_trip_details_weekend_encoded_sharmi
where trip_fare is not null and trip_miles is not null and trip_seconds is not null
group by to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd')),
from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'u'),
from_unixtime(to_unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'MMM'),
year(to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd'))),
Weekend,
round(trip_fare), 
round(trip_miles), 
round(trip_seconds/60)) T
group by Date,
Day_Of_Week,
Month,
Year,
Weekend;

因此,使用以下查询解决了该问题:

CREATE TABLE IF NOT EXISTS Daily_Summary_Table
STORED AS ORC 
AS
Select Date,
Day_Of_Week,
Month,
Year,
Weekend,
sum(mult_fare)/count(*) as avg_wt_trip_fare,sum(mult_miles)/count(*) as avg_wt_trip_miles, sum(mult_dur) /count(*) as avg_wt_trip_dur
from(
select to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd')) Date,
from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'u') Day_Of_Week,
from_unixtime(to_unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'MMM') Month,
year(to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd'))) Year,
Weekend, 
count(trip_id_int),
count(round(trip_fare)),
count(round(trip_miles)),
count(round(trip_seconds/60)),
count(taxi_id_int)*round(trip_fare) mult_fare, 
count(taxi_id_int)*round(trip_miles) mult_miles, 
count(taxi_id_int)*round(trip_seconds/60) mult_dur
from chicago_taxis.taxi_trip_details_weekend_encoded_sharmi
where trip_fare is not null and trip_miles is not null and trip_seconds is not null
group by to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd')),
from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'u'),
from_unixtime(to_unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'MMM'),
year(to_date(from_unixtime(unix_timestamp(split(trip_start_time, " ")[0], 'MM/dd/yyyy'), 'yyyy-MM-dd'))),
Weekend,
round(trip_fare), 
round(trip_miles), 
round(trip_seconds/60)) T
group by Date,
Day_Of_Week,
Month,
Year,
Weekend;

如错误所示,select中的某些表达式不在group by中expression@mck我知道,但哪把钥匙我不懂。但是,我没有包括count字段。子查询T包含没有group by的coontains聚合。主查询包含具有组的聚合,该组似乎应位于子查询中T@leftjoin因此,我修改了查询以将group by包含在子查询中,现在我得到了以下错误失败:SemanticException行0:-1表达式不在group by key“as”中。有人可以提供帮助吗?如错误所示,select中的某些表达式不在group by中expression@mck我知道,但哪把钥匙我不懂。但是,我没有包括count字段。子查询T包含没有group by的coontains聚合。主查询包含具有组的聚合,该组似乎应位于子查询中T@leftjoin因此,我修改了查询以将group by包含在子查询中,现在我发现此错误失败:SemanticException行0:-1表达式不在group by key“as”中。有人可以提供帮助吗?