记录一个HiveSQL语句报错问题

[42000][40000] Error while compiling statement: FAILED: SemanticException Line 0:-1 Unsupported SubQuery Expression ''语文'': Nested SubQuery expressions are not supported.

遇到的错误信息 [42000][40000] Error while compiling statement: FAILED: SemanticException Line 0:-1 Unsupported SubQuery Expression ''语文'': Nested SubQuery expressions are not supported. 表明所使用的数据库系统或查询引擎不支持嵌套子查询,或者在特定上下文中不支持这样的表达式。

原SQL:

-- 2. 查询一共参加三门课程且其中一门为语文课程的学生的id和姓名
select
    t1.stu_id,
    stu_name
from student_info t1
        join
    (
         select stu_id,
                count(score_info.course_id) cc
         from score_info
         where stu_id in (select stu_id
                          from score_info
                          where course_id = (select course_id from course_info where course_name = '语文'))
         group by stu_id
         having cc = 3
    ) t2
on
    t1.stu_id = t2.stu_id;

正确运行SQL:

-- 2. 查询一共参加三门课程且其中一门为语文课程的学生的id和姓名
select
    t1.stu_id,
    stu_name
from student_info t1
        join
    (
         select stu_id,
                count(*) cc
         from score_info
         where stu_id in (select stu_id
                          from score_info
                          where course_id = (select course_id from course_info where course_name = '语文'))
         group by stu_id
         having cc = 3
    ) t2
on
    t1.stu_id = t2.stu_id;

其中区别仅在:

结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值