我很难将计数之和作为配置单元sql中联合表的结果进行组合
SELECT pulocation AS locID,count(pulocation) AS puCount FROM task1
WHERE distance > 0.5 AND distance < 1
GROUP BY pulocation
UNION
SELECT dolocation,count(dolocation) AS doCount FROM task1
WHERE distance > 0.5 AND distance < 1
GROUP BY dolocation
会给我这张table的结果吗
_u2.locid _u2.pucount
1 18
1 24
3 3
3 4
4 4693
我试图把这个表创建一个新的组合计数表,但没有成功。
SELECT _u2.locid, SUM(_u2.pucount)
FROM (
SELECT pulocation AS locID,count(pulocation) AS puCount FROM task1
WHERE distance > 0.5 AND distance < 1
GROUP BY pulocation
UNION
SELECT dolocation,count(dolocation) AS doCount FROM task1
WHERE distance > 0.5 AND distance < 1
GROUP BY dolocation)
GROUP BY u2.locid
我尝试使用'u2'或'u2'。但导致了这个错误
org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 14:0 Failed to recognize predicate 'GROUP'. Failed rule: 'identifier' in subquery source
我最想要的就是这张table
_u2.locid _u2.pucount
1 42
3 7
4 4693
3条答案
按热度按时间ubby3x7f1#
这就是你需要的
SELECT locID, sum(totCount) as totCount FROM ( SELECT pulocation AS locID,count(pulocation) AS totCount FROM task1 WHERE distance > 0.5 AND distance < 1 GROUP BY pulocation UNION ALL SELECT dolocation AS locID,count(dolocation) AS totCount FROM task1 WHERE distance > 0.5 AND distance < 1 GROUP BY dolocation ) t1 GROUP BY locID
5ssjco0h2#
在前面答案的帮助下,
sshcrbum3#
尝试以下方式: