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 / mahesh raja

SEL STUDENTID,STUDENTNAME,MARKS, SBJ,RANK()OVER (PARTITION
BY STUDENTID ORDER BY MARKS DESC ) AS RANK1 FROM
(
SEL STUDENTID,STUDENTNAME,SUBJECT1 AS MARKS, 'SUB1' AS SBJ
FROM STUD1
UNION
SEL STUDENTID,STUDENTNAME,SUBJECT2 AS MARKS, 'SUB2' AS SBJ
FROM STUD1
UNION
SEL STUDENTID,STUDENTNAME,SUBJECT3 AS MARKS, 'SUB3' AS SBJ
FROM STUD1
)A QUALIFY RANK1=1

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens in a conflict? How do you handle that?

612


What are the steps involved in the process flow of the sql statement through channel attached system?

653


What is the difference between fastload and multiload? Which one is faster?

588


Why do you get spool space errors? How do trouble-shoot them?

581


List out teradata data types?

551






Explain and compare pros and cons of start schemas?

535


What is the purpose of upsert command?

586


What is teradata?

635


How do you do backup and recovery in teradata?

536


What is stored procedure in teradata?

575


How to view every column and the columns contained in indexes in teradata?

580


What is spool space?

593


Highlight the advantages of PPI(Partition Primary Index).

557


Difference between star and snowflake schemas?

596


What are different table types used in teradata?

577