i have column like below
studentid studentname sub1 sub2 sub3
1 aaa 40 70 90
2 bbb 60 80 50
i want to execute every student highest mark in which subject
my o/p like below
studentid studentname sub3 sub2
1 aaa 90
2 bbb 80
Answer Posted / tdguy
SEL A.STUDENTID,A.STUDENTNAME,
CASE WHEN A.HIGHSUBJ='SUBJECT1'
THEN B.SUBJECT1
ELSE C.SUBJECT1
END AS SUBJECT1,
CASE WHEN A.HIGHSUBJ='SUBJECT2'
THEN B.SUBJECT2
ELSE C.SUBJECT2
END AS SUBJECT2,
CASE WHEN A.HIGHSUBJ='SUBJECT3'
THEN B.SUBJECT3
ELSE C.SUBJECT3
END AS SUBJECT3
FROM
(SEL STUDENTID,STUDENTNAME,SUBJECT1 ,SUBJECT2 ,SUBJECT3,
CASE WHEN SUBJECT1 > SUBJECT2 AND SUBJECT1 > SUBJECT3
THEN 'SUBJECT1'
WHEN SUBJECT2 > SUBJECT3
THEN 'SUBJECT2' ELSE 'SUBJECT3'
END AS HIGHSUBJ
FROM STUD1) A
INNER JOIN
(SEL STUDENTID,STUDENTNAME,SUBJECT1 ,SUBJECT2 ,SUBJECT3
FROM STUD1) B
ON A.STUDENTID=B.STUDENTID
INNER JOIN
(SEL STUDENTID,STUDENTNAME,NULL AS SUBJECT1 ,
NULL AS SUBJECT2 ,
NULL AS SUBJECT3 FROM STUD1) C
ON B.STUDENTID=C.STUDENTID
ORDER BY A.STUDENTID
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What happens when a node suffers a downfall?
Discuss the advantages of using partitioned primary index in a query?
what is object level locking ? where do appear this type of locking ?
Explain the new features of teradata?
What is a dimension table?
What is bteq utility in teradata?
Explain the meaning of Amp?
What is teradata? What are some primary characteristics of teradata?
How to write the query . eid enm doj dob i want to display the names who worked more than 25 years .
Explain some differences between mpp and smp?
Explain how spool space is used.
any one answer me how they can analyzing the project using data ware housing?
Explain the term 'columns' related to relational database management system?
What is spool space? Why do you get spool space errors? How do trouble-shoot them?
What are the things to be considered while creating secondary index?