Relational Queries questions

Q23

GATE CS 2017 CS-1Relational QueriesNAT1 mark
Consider a database that has the relation schema EMP(EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below.
EmpIdEmpNameDeptName
1XYAAA
2XYBAA
3XYCAA
4XYDAA
5XYEAB
6XYFAB
7XYGAB
8XYHAC
9XYIAC
10XYJAC
11XYKAD
12XYLAD
13XYMAE
SELECT AVG(EC.Num)
FROM EC
WHERE (DeptName, Num) IN
    (SELECT DeptName, COUNT(EmpId) AS
                    EC(DeptName, Num)
     FROM EMP
     GROUP BY DeptName)
The output of executing the SQL query is ____________.
Show answer without attempting

Answer: 2.6

Q41

GATE CS 2017 CS-1Relational QueriesMCQ2 marks−2/3 if wrong
Consider a database that has the relation schemas EMP(EmpId, EmpName, DeptId), and DEPT(DeptName, DeptId). Note that the DeptId can be permitted to be NULL in the relation EMP.
Consider the following queries on the database expressed in tuple relational calculus.

(I) {t∣∃u∈EMP(t[EmpName]=u[EmpName]∧∀v∈DEPT(t[DeptId]≠v[DeptId]))}\lbrace t \mid \exists u \in \text{EMP}(t[\text{EmpName}] = u[\text{EmpName}] \land \forall v \in \text{DEPT}(t[\text{DeptId}] \neq v[\text{DeptId}])) \rbrace
(II) {t∣∃u∈EMP(t[EmpName]=u[EmpName]∧∃v∈DEPT(t[DeptId]≠v[DeptId]))}\lbrace t \mid \exists u \in \text{EMP}(t[\text{EmpName}] = u[\text{EmpName}] \land \exists v \in \text{DEPT}(t[\text{DeptId}] \neq v[\text{DeptId}])) \rbrace
(III) {t∣∃u∈EMP(t[EmpName]=u[EmpName]∧∃v∈DEPT(t[DeptId]=v[DeptId]))}\lbrace t \mid \exists u \in \text{EMP}(t[\text{EmpName}] = u[\text{EmpName}] \land \exists v \in \text{DEPT}(t[\text{DeptId}] = v[\text{DeptId}])) \rbrace

Which of the above queries are safe?
Show answer without attempting

Answer: D

Q46

GATE CS 2017 CS-1Relational QueriesNAT2 marks
Consider a database that has the relation schema CR(StudentName, CourseName). An instance of the schema CR is as given below.
StudentNameCourseName
SACA
SACB
SACC
SBCB
SBCC
SCCA
SCCB
SCCC
SDCA
SDCB
SDCC
SDCD
SECD
SECA
SECB
SFCA
SFCB
SFCC
The following query is made on the database.

T1←πCourseName(σStudentName=′SA′(CR))T1 \leftarrow \pi_{\text{CourseName}}(\sigma_{\text{StudentName} = '\text{SA}'}(\text{CR}))
T2←CR÷T1T2 \leftarrow \text{CR} \div T1

The number of rows in T2T2 is ____________.
Show answer without attempting

Answer: 4.0

Q46

GATE CS 2017 CS-2Relational QueriesNAT2 marks
Consider the following database table named top_scorer.
playercountrygoals
KloseGermany16
RonaldoBrazil15
G MüllerGermany14
FontaineFrance13
PeléBrazil12
KlinsmannGermany11
KocsisHungary11
BatistutaArgentina10
CubillasPeru10
LatoPoland10
LinekerEngland10
T MüllerGermany10
RahnGermany10
Consider the following SQL query:
SELECT ta.player FROM top_scorer AS ta
WHERE ta.goals > ALL (SELECT tb.goals
                        FROM top_scorer AS tb
                        WHERE tb.country = 'Spain')
AND ta.goals > ANY (SELECT tc.goals
                    FROM top_scorer AS tc
                    WHERE tc.country = 'Germany')
The number of tuples returned by the above SQL query is ____________.
Show answer without attempting

Answer: 7.0

0/40 correct0 marks

Related topics in Databases