You are on page 1of 5

29th ITPEC FE Afternoon Exam -- 2020


 
The following SQL statement “SQL1” outputs the customer ID, name, and exam count of
the customers who took the examination three times or more between January 1, 2020 and March
31, 2020.

Answer group for A


a) AND (ExamDate >= '2020-01-01' OR ExamDate <= '2020-03-31')
GROUP BY Customer.CustomerID, Customer.Name
HAVING COUNT(*) >= 3
b) AND ExamDate >= '2020-01-01' AND ExamDate <= '2020-03-31' AND COUNT(*) >= 3
c) AND ExamDate BETWEEN '2020-01-01' AND '2020-03-31'
GROUP BY Customer.CustomerID, Customer.Name
HAVING COUNT(*) >= 3
d) GROUP BY Customer.CustomerID, Customer.Name, ExamDate
HAVING ExamDate >= '2020-01-01' AND ExamDate <= '2020-03-31'
AND COUNT(*) >= 3


 
The clinic wants to identify the exam status of a customer. The exam status will be either
“Ended” or “Follow-up”, depending on whether the result of the latest examination was OK or
NG. The following SQL statement “SQL2” outputs the exam status of the customer whose ID is
20030495.

The CASE statement goes through conditions and return a value when the first condition
is met (like an IF-THEN-ELSE statement). So, once a condition is true, it will stop reading and
return the result.
If no conditions are true, it will return the value in the ELSE clause.
If there is no ELSE part and no conditions are true, it returns NULL.
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;


 
For Example,
SELECT OrderID, Quantity,
CASE
WHEN Quantity > 30 THEN "The quantity is greater than 30"
WHEN Quantity = 30 THEN "The quantity is 30"
ELSE "The quantity is under 30"
END
FROM OrderDetails;

Answer group for B


a) Examination.Result = 'NG' THEN 'Ended' ELSE 'Follow-up'
b) Examination.Result = 'NG' THEN 'Follow-up'
WHEN Examination.Result != 'NG' THEN 'Ended'
c) Examination.Result != 'NG' THEN 'Ended' OTHERWISE 'Follow-up'
d) Examination.Result != 'NG' THEN 'Follow-up'
WHEN Examination.Result = 'NG' THEN 'Ended'

Answer group for C


a) DISTINCT Examination.ExamDate
b) Examination.ExamDate
c) MAX(Examination.ExamDate)
d) MIN(Examination.ExamDate)

The clinic is developing the following SQL statement “SQL3” that will output the number
of customers who are babies under 90 days old at the present time and took the examination(s).
Here, the function DATEDIFF(day, date1, date2) returns the difference, in days, between
date1 and date2, and the function GETDATE() returns the current date.


 
Answer group for D
a) adding LIMIT 1 after line 5
b) changing COUNT(Customer.CustomerID) to COUNT(*) on line2
c) changing COUNT(Customer.CustomerID) to COUNT(*) on line2 and adding LIMIT 1 after
line 5
d) changing COUNT(Customer.CustomerID) to COUNT(DISTINCT Customer.CustomerID) on
line 2


 

You might also like