Skip to content
Question
Q.

Consider the table Patient given below and write SQL commands. Table : Patient

Patient idNameCityPhoneDate of admDepartment
1000001Ritvik GargDelhi684762132021-12-10Surgery
1000002Rahil AroraMumbai365463212022-01-08Medicine
1000003Mehak BhattDelhi684218792022-02-02Cardiology
1000004Soumik RaoDelhi265432662022-01-11Medicine
1000005Suresh SoodBangalore654324422021-03-09Surgery

(i) Display the details of all patients who were admitted in January. (ii) Count the total number of patients from Delhi. (iii) Display the last 2 digits of the Patient id of all patients from Surgery Department.

CBSECBSE Class XII Board 2023Subjective· 3mImportance★★★★★
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

This response provides SQL commands to retrieve patient details based on admission date, count patients from a specific city, and extract parts of patient IDs, demonstrating fundamental SQL data manipulation and string/date functions.

In the realm of database management, SQL (Structured Query Language) is the universal language for interacting with relational databases. It allows us to define, manipulate, and query data efficiently. When working with tables like Patient, we often need to filter records, aggregate information, or transform data within columns. This involves using various SQL clauses and functions, including those specifically designed for handling dates and strings.

Let's break down the requirements and construct the appropriate SQL commands.

(i) Display the details of all patients who were admitted in January.

To achieve this, we need to filter the Patient table based on the month of admission. The Date of adm column stores the admission date. SQL provides functions to extract specific parts of a date. A common function to get the month number from a date is MONTH(). We will select all columns (*) from the Patient table where the month extracted from Date of adm is 1 (representing January).

Note

Different SQL database systems might use slightly different functions for date extraction. For instance, EXTRACT(MONTH FROM "Date of adm") is common in PostgreSQL, while STRFTIME('%m', "Date of adm") is used in SQLite. MONTH() is a widely recognized function in many SQL environments, including MySQL and SQL Server, and is often used in NCERT examples for simplicity.

SELECT *
FROM Patient
WHERE MONTH("Date of adm") = 1;

(ii) Count the total number of patients from Delhi.

This query requires two main steps: first, filtering the patients to include only those from 'Delhi', and second, counting the number of records that satisfy this condition. The WHERE clause is used for filtering, and the COUNT() aggregate function is used to count rows. COUNT(*) counts all rows that meet the specified criteria.

COUNT(*): This aggregate function returns the total number of rows in a table or the number of rows that satisfy a specified WHERE clause.

SELECT COUNT(*)
FROM Patient
WHERE City = 'Delhi';

(iii) Display the last 2 digits of the Patient id of all patients from Surgery Department. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.