0

如何在avg结果的左侧有别名?

我有这个平均子查询

SELECT AVG(GRADE) AS GRADE
  FROM (
         SELECT AVG(NUMERIC_GRADE) AS GRADE
           FROM GRADE
          WHERE STUDENT_ID = 5 
            AND SECTION_ID = 17
          GROUP BY GRADE_TYPE_CODE
       ) myInnerTable;

我得到了一个结果

     GRADE
----------
      82.3

我想将它与我的平均结果结合起来,我必须使用另一列吗?

SELECT INITCAP(GRADE_TYPE_CODE) AS "Average is:"
  FROM GRADE;

我想要这样的东西

GRADE_TYPE_CODE         GRADE
----------------------- ------
Average Is:             82.3
4

1 回答 1

2

请试试:

SELECT 
    'Average Is:' AS GRADE_TYPE_CODE,
    AVG(GRADE) AS GRADE
FROM
(
    SELECT AVG(NUMERIC_GRADE) AS GRADE
FROM GRADE
WHERE STUDENT_ID = 5 AND SECTION_ID = 17
GROUP BY GRADE_TYPE_CODE
) myInnerTable;
于 2013-11-01T05:26:49.197 回答