The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+12 votes
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.

asked in Databases by Veteran (59.6k points)
edited by | 653 views

2 Answers

+21 votes
Best answer
  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 

answered by Active (4.9k points)
edited by
+1
Registered For

        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;

0 votes

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.

answered by (389 points)
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
what is your answr.? @pujaa
0
Same as best answer .... hav u run that query ??

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,599 questions
48,600 answers
155,672 comments
63,739 users