Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Oracle查询中的错误需要更正_Sql_Oracle - Fatal编程技术网

Sql Oracle查询中的错误需要更正

Sql Oracle查询中的错误需要更正,sql,oracle,Sql,Oracle,我想按每个学生的学分分别分组计算所有学生的学分? 需要帮助更正查询 select distinct altcode,name, ( SELECT sum(CRHRS) FROM V_ALLSTUDATA WHERE grades in ('A','A+','B','B+','C','C+','D','D+') group by altcode ) as completed_credit_hours, (select sum(crhrs)

我想按每个学生的学分分别分组计算所有学生的学分? 需要帮助更正查询

select distinct altcode,name,
(
SELECT sum(CRHRS)
      FROM V_ALLSTUDATA 
      WHERE grades in ('A','A+','B','B+','C','C+','D','D+')
      group by altcode
    ) as completed_credit_hours,
    (select sum(crhrs)
      from V_ALLSTUDATA
       where grades is null
        group by altcode
    ) as registerd_credit_hours
from V_ALLSTUDATA
where sem_code like'%FALL-19%'
      group by altcode,name;

试试这个:

select distinct altcode,name,
(
SELECT sum(CRHRS)
      FROM V_ALLSTUDATA b
      WHERE grades in ('A','A+','B','B+','C','C+','D','D+') and a.name = b.name and a.altcode= b.altcode

    ) as completed_credit_hours,
    (select sum(crhrs)
      from V_ALLSTUDATA b
       where grades is null  and a.name = b.name and a.altcode= b.altcode

    ) as registerd_credit_hours
from V_ALLSTUDATA a
where sem_code like'%FALL-19%';

我认为您需要
条件聚合
来简化查询:

select altcode,name,
       sum(case when grades in ('A','A+','B','B+','C','C+','D','D+') then CRHRS end) as completed_credit_hours,
       sum(case when grades is null then crhrs end) as registerd_credit_hours
from V_ALLSTUDATA
where sem_code like'%FALL-19%'
      group by altcode,name;

干杯

非常感谢,这很有效。非常感谢,亲爱的,现在我想通过已完成小时数+已注册小时数的总和,再加上下一列已注册小时数来计算总小时数???/怎么做。