2016-12-15 14 views
-3

でPIVOT演算子を使用して、私はSchool_Name、CLASS_CODE、STUDENT_CODE、STUDENT_NAME、KANNADA ASこのオラクル

SELECT * FROM 
(
    SELECT STUDENT_NAME,subject_code ,TERM_I_GRADE FROM tablename 
) 
PIVOT 
(
TERM_I_GRADE 
    FOR subject_code IN (2001,2002) 
) 
ORDER BY STUDENT_NAME; 
std_code Student_Name subject_code TERM_I_GRADE 
9  Kishan  2003   A 
9  Kishan  2001   A 
9  Kishan  2002   A 
9  Kishan  2007   A 
9  Kishan  2004   A 

output 
------------------- 
stdcode Student_Name 2003 2001 2002 2007 2004 
9  Kishan  A  A A  A A 
+1

あなたの質問は何ですか? –

+0

私はこの出力のような出力が必要です ------------------- stdcode学生名2003 2001 2002 2007 2004 9 Kishan AAAAA – kumarh

+0

PIVOTに集合関数がありません。 –

答えて

2
select * 
from mytable pivot (max(TERM_I_GRADE) for subject_code in (2003,2001,2002,2007,2004)) p 

+----------+--------------+------+------+------+------+------+ 
| STD_CODE | STUDENT_NAME | 2003 | 2001 | 2002 | 2007 | 2004 | 
+----------+--------------+------+------+------+------+------+ 
| 9  | Kishan  | A | A | A | A | A | 
+----------+--------------+------+------+------+------+------+ 
0

SELECT YEAR_CODE、 'HAVALGA' のようなピボットを使用、ENGLISH、HINDI、MATHS、SCIENS、SOCIAL、EVS (SELECT 、class_ KANNADA AS 2001(IN SUBJECT_CODEためのコード、STUDENT_CODE、STUDENT_NAME、 SUBJECT_CODE、
SCHOOL_CODE = 1301とYEAR_CODE = '2016から2017'

) PIVOT(MAX(TERM_I_GRADE)SRSDF_EXAM_TERM_I FROM TERM_I_GRADEとしてTERM_I_GRADE 、2002 AS ENGLISH、 2003 AS HINDI、2004 AS MATHS、 2005 ASサイエンス、2006 ASSOCIAL、 2007 AS EVS)) ORDER BY class_code、STUDENT_CODE;