653 views

Consider the following relational schema:

• COURSES (cno, cname)
• STUDENTS (rollno, sname, age, year)
• REGISTERED FOR (cno, rollno)

The underlined attributes indicate the primary keys for the relations. The ‘year’ attribute for the STUDENTS relation indicates the year in which the student is currently studying (First year, Second year etc.)

1. Write a relational algebra query to print the roll number of students who have registered for cno 322.

2. Write a SQL query to print the age and year of the youngest student in each year.

edited | 653 views

1. $π_{roll\_no}.(σ_{cno.}=_{322}$(registered for))
2. SELECT year,min(age)

FROM students

GROUP BY year

in second question we hav to find year nd youngest student from that year so, we have to apply  minn aggregate function on group of year

edited by
+1
 Cno Rno 122 1 322 2 123 3

I have doubt in REGISTERED FOR Table. Cno is primary key, it means a course can be enrolled only by one student??

+1

The above may be useful.

0
ayush so i can write select year ,age

from student

group by year ,

having (min (age) ) it wil give error ? due to select and group does not have same attribute ?
0

What would be the query if i need "sname,age,year"  of the youngest student in each year.
i tried below, but this is wrong

SELECT SNAME,YEAR,MIN(AGE) FROM STUDENTS GROUP BY YEAR,SNAME;

1).  (a)πroll_no.cno.=322(registered for))

2.) select age , year from student s1 where not exists(select s2.age from student s2 where s2.age > s1.age) group by year.

0
I think ur query is wrong ... it will select those students of every year who is smaller than the age of older student in their respective year ...
0
0
Same as best answer .... hav u run that query ??

1
2