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 / yuvaevergreen

CREATE TABLE STUD1
(
STUDENTID CHAR(10), STUDENTNAME CHAR(10),
SUBJECT1 INTEGER, SUBJECT2 INTEGER,
SUBJECT3 INTEGER
)PRIMARY INDEX( STUDENTID );
INSERT INTO STUD1 VALUES ('1','A1',2,7,1);
INSERT INTO STUD1 VALUES ('2','A2',1,6,2);
INSERT INTO STUD1 VALUES ('3','A3',3,5,3);
INSERT INTO STUD1 VALUES ('4','A4',4,4,7);
INSERT INTO STUD1 VALUES ('5','A5',5,3,6);

QUERY TO FETCH THE STUDENTS TOPPED IN ALL THE THREE SUBJECTS

SEL STUDENTID,STUDENTNAME,SUBJECT1,SUBJECT2,SUBJECT3
FROM
(
SEL STUDENTID,STUDENTNAME,SUBJECT1,SUBJECT2,SUBJECT3,
RANK () OVER (ORDER BY SUBJECT1 DESC) as SUB1RANK,
RANK () OVER (ORDER BY SUBJECT2 DESC) as SUB2RANK,
RANK () OVER (ORDER BY SUBJECT3 DESC) as SUB3RANK
FROM STUD1 QUALIFY (SUB1RANK=1 OR SUB2RANK=1 OR SUB3RANK=1 )) A

Is This Answer Correct ?    7 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between stored procedure and macro?

695


What is the syntax for case when statement?

598


Explain how spool space is used.

625


What are the steps involved after the disk manager passes the request?

589


how do we write scripts in unix how to execute scripts in real time anybody please needfull or give me number i will cal u

1284






Write a program to show the parser component used in teradata?

561


Describe the between keyword in teradata?

620


A certain load is being imposed on the table and that too, every hour. The traffic in the morning is relatively low, and that of the night is very high. As per this situation, which is the most advisable utility and how is that utility supposed to be loaded?

697


What are the various indexes in teradata? How to use them? Why are they preferred?

603


What is oltp?

578


How can we check the version of Teradata that we are using currently?

601


How to load specific no.of records using bteq, or fastload,or multiload

1325


How would you load a very large file in teradata in general?

575


What is the purpose of upsert command?

599


Which is faster fastload or multiload?

604