0% found this document useful (0 votes)
32 views2 pages

SQL Assessment Test Questions and Tasks

This document contains instructions for an SQL assessment test consisting of 3 sections with multiple choice and written response questions. Section I contains 5 multiple choice questions. Section II contains 10 questions requiring SQL queries as answers. Section III contains 5 questions requiring more complex SQL queries. The test covers topics such as data manipulation statements, joins, aggregations, and filtering records based on multiple conditions.

Uploaded by

Sasirekha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

SQL Assessment Test Questions and Tasks

This document contains instructions for an SQL assessment test consisting of 3 sections with multiple choice and written response questions. Section I contains 5 multiple choice questions. Section II contains 10 questions requiring SQL queries as answers. Section III contains 5 questions requiring more complex SQL queries. The test covers topics such as data manipulation statements, joins, aggregations, and filtering records based on multiple conditions.

Uploaded by

Sasirekha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

LEAD – SQL ASSESSMENT TEST Marks :50

Time : 3hrs

I. Answer the following questions: 5*1 =5

1. What is returned by SUBSTR(‘Oracle Functions’, -1, 1)?

2. Which of the following is true about removing rows from a table?


A - You remove existing rows from a table using the DELETE statement
B - No rows are deleted if you omit the WHERE clause.
C - You cannot delete rows based on values from another table.
D - All of the above.
3. Which of the following is not true about a FOREIGN KEY constraint?
A - It is a referential integrity constraint.
B - It establishes a relationship between a primary key or a unique key in the same table or a
different table.
C - A foreign key value cannot be null.
D - A foreign key value must match an existing value in the parent table.

4. Which SQL keyword is used to retrieve only unique values ?


DISTINCT
DIFFERENT
UNIQUE
DISTINCTIVE

5. Which of the following is illegal ?


SELECT SYSDATE - (SYSDATE - 2) FROM DUAL;
SELECT SYSDATE - (SYSDATE + 2) FROM DUAL;
SELECT SYSDATE - SYSDATE FROM DUAL;
None of the above

II. Answer the following 10*3=30

1. Explain the different methods/ Syntax to insert the records in to a table.

2. Update the patients table for the allergies column. If the patient's allergies is null then replace it with
'NKA'

3. Show how many patients have a birth_date with 2010 as the birth year.

4. Show the first_name, last_name, and height of the patient with the greatest height.

5. Show all columns for patients those who have patient_ids are in even number

6. Show patient details(patient name, gender, diagnosis, no. of times came for the dignosis) those who
came for same diagnosis multiple times

7. Show patient_id and first_name from patients where their first_name start and ends with 's' and is at
least 6 characters long.

8. Show firstname, last name , role from patients and Doctors table

Role should be “Patient” if data is from Patient table


Role should be “Doctor” if data is from Doctors table.

9. Show first_name, last_name, and the total number of admissions attended for each doctor.

10. For each doctor, display their id, full name, and the first and last admission date they attended.

III. Answer the following 5*3=15

1. All patients who have gone through admissions, can see their medical documents on our site. Those
patients are given a temporary password after their first admission. Show the patient_id and
temp_password.
The password must be the following, in order:
1. patient_id
2. the numerical length of patient's last_name
3. year of patient's birth_date

2. a. Show the percent of patients Gender

b. We need a breakdown for the total amount of admissions each doctor has started each year. Show the
doctor_id, doctor_full_name, specialty, year, total_admissions for that year.

3. We are looking for a specific patient. Pull all columns for the patient who matches the following criteria:
- First_name contains an 'r' after the first two letters.
- Identifies their gender as 'F'
- Born in February, May, or December
- Their weight would be between 60kg and 80kg
- Their patient_id is an odd number
- They are from the city 'Kingston'

Common questions

Powered by AI

To tailor patient search queries in SQL for specific criteria, use complex WHERE clauses incorporating multiple conditions. For example, 'SELECT * FROM patients WHERE SUBSTRING(first_name FROM 3) LIKE '%r%' AND gender = 'F' AND EXTRACT(MONTH FROM birth_date) IN (2, 5, 12) AND weight BETWEEN 60 AND 80 AND MOD(patient_id, 2) = 1 AND city = 'Kingston';'. This query filters records based on name, gender, birth month, weight range, odd patient_id, and city, utilizing SQL's pattern matching and logical operators .

A FOREIGN KEY constraint is important in SQL for maintaining referential integrity between tables by ensuring that a value in one table corresponds to a value in another table. Misconceptions include the belief that a foreign key value cannot be null, whereas it can indeed be null if set up that way, and that it must always match an existing value in the referenced table, which is true. It also establishes a relationship with primary or unique keys in either the same or different tables .

SQL can be utilized to present structured information about doctors by joining relevant tables and summarizing data. For instance, 'SELECT d.doctor_id, CONCAT(d.first_name, ' ', d.last_name) AS doctor_full_name, MIN(a.admission_date) AS first_admission, MAX(a.admission_date) AS last_admission FROM doctors d JOIN admissions a ON d.doctor_id = a.doctor_id GROUP BY d.doctor_id, d.first_name, d.last_name;'. This combines personal doctor information with admission records to give each doctor's active and detailed history .

To generate passwords for patients based on specific details, use a SQL concatenation: 'SELECT patient_id, CONCAT(patient_id, LENGTH(last_name), EXTRACT(YEAR FROM birth_date)) AS temp_password FROM admissions;'. This method combines patient ID, last name length, and birth year to create a potentially secure and unique temporary password. The composition is significant as it creates easily remembered and unique passwords enhancing patient security .

To query a SQL database for records where both the first and last names meet specific conditions, such as starting and ending with 's' and being at least 6 characters long, you can use the following query: 'SELECT patient_id, first_name FROM patients WHERE first_name LIKE 's____%' AND first_name LIKE '%s' AND LENGTH(first_name) >= 6;'. This utilizes pattern matching with the LIKE operator and length conditions to filter results based on precise character requirements .

To derive demographic insights regarding gender distribution from a patient database, use SQL's GROUP BY and aggregation features. For example, 'SELECT gender, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM patients) AS percent FROM patients GROUP BY gender;' This query computes the percentage of each gender in relation to the whole dataset, providing actionable demographic insight .

There are several methods to insert records into a SQL table, primarily through the INSERT INTO statement. The simplest form is 'INSERT INTO table_name VALUES (value1, value2, ...);', which requires specifying values for all columns. Another method is 'INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);', which allows for inserting only into specific columns. The 'INSERT INTO table_name SELECT ...' form is used to insert data from another query's result set. The choice of method depends on whether specific columns need to be populated or a whole row from another table is required .

The SQL keyword 'DISTINCT' is used to retrieve only unique rows from a dataset. It is critical in data analysis for eliminating duplicate entries and ensuring that the analysis is based on distinct records, which is essential for accurate results .

To update a SQL table to replace NULL values in a column, use the UPDATE statement with a SET clause. For example, 'UPDATE patients SET allergies = 'NKA' WHERE allergies IS NULL;' will change the 'allergies' column to 'NKA' where it is currently NULL. This ensures that any NULL entries are replaced by a specified default value .

To determine the total number of admissions a doctor has attended each year, use a combination of GROUP BY and aggregation functions: 'SELECT doctor_id, doctor_full_name, specialty, EXTRACT(YEAR FROM admission_date) AS year, COUNT(admission_id) AS total_admissions FROM admissions GROUP BY doctor_id, doctor_full_name, specialty, EXTRACT(YEAR FROM admission_date);'. This groups the data by doctor and year, counting admissions for each group .

You might also like