0% found this document useful (0 votes)
384 views5 pages

Patient Data Queries in MySQL

This document contains 6 SQL queries with their corresponding answers: (a) displays all information from patients in the cardiology department, (b) lists names of female patients in orthopedics, (c) lists all patient names and admission dates in ascending order, (d) displays name, charges, and age for male patients only, (e) counts patients over age 20, (f) repeats the first query to display all information from cardiology patients.

Uploaded by

Rohan Kotian
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)
384 views5 pages

Patient Data Queries in MySQL

This document contains 6 SQL queries with their corresponding answers: (a) displays all information from patients in the cardiology department, (b) lists names of female patients in orthopedics, (c) lists all patient names and admission dates in ascending order, (d) displays name, charges, and age for male patients only, (e) counts patients over age 20, (f) repeats the first query to display all information from cardiology patients.

Uploaded by

Rohan Kotian
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
  • Hospital Table SQL Queries
  • Orthopedic Department Queries
  • Date Admission Queries
  • Age Count Query
  • Patient's Name Display

MySQL Worksheet - 2

(a) To show all information about the patients of cardiology department.

(b) To list the names of female patients who are in orthopedic dept.

(c) To list names of all patients with their date of admission in


ascending order.

(d) To display Patient’s Name, Charges, age for male patients only.

(e) To count the number of patients with age >20.

(b) To show all information


about the patients of
cardiology department.
Ans: SELECT * FROM
hospital WHERE
department=’Cardiology’;
(c ) To list the names of
female patients who are in
orthopedic dept.
Ans: SELECT name FROM
hospital WHERE sex=’F’
AND
department=’Orthopedic’;
(d) To list names of all
patients with their date of
admission in ascending order.
Ans.: SELECT name,
dateofadm FROM hospital
ORDER BY dateofadm;
(e) To display Patient’s Name,
Charges, age for male patients
only.
Ans: SELECT name, charges,
age FROM hospital WHERE
sex=’M’;
(f) To count the number of
patients with age >20.
Ans.: SELECT COUNT(age)
FROM hospital WHERE
age>20;
(b) To show all information
about the patients of
cardiology department.
Ans: SELECT * FROM
hospital WHERE
department=’Cardiology’;
(c ) To list the names of
female patients who are in
orthopedic dept.
Ans: SELECT name FROM
hospital WHERE sex=’F’
AND
department=’Orthopedic’;
(d) To list names of all
patients with their date of
admission in ascending order.
Ans.: SELECT name,
dateofadm FROM hospital
ORDER BY dateofadm;
(e) To display Patient’s Name,
Charges, age for male patients
only.
Ans: SELECT name, charges,
age FROM hospital WHERE
sex=’M’;
(f) To count the number of
patients with age >20.
Ans.: SELECT COUNT(age)
FROM hospital WHERE
age>20;

Common questions

Powered by AI

The SQL command to count the number of patients with age greater than 20 is: SELECT COUNT(age) FROM hospital WHERE age>20;

The query to list all patients sorted by their date of admission in ascending order is: SELECT name, dateofadm FROM hospital ORDER BY dateofadm;

The SQL query to show all details of patients in the cardiology department is: SELECT * FROM hospital WHERE department='Cardiology';

The ORDER BY clause is important for organizing queried data into a readable and ordered format based on specified criteria, such as arranging patient data by date of admission which aids in data analysis and review.

To ensure selection of only female orthopedic patients, you would use a WHERE clause specifying both conditions: sex='F' and department='Orthopedic', e.g., SELECT name FROM hospital WHERE sex='F' AND department='Orthopedic';

Specifying multiple conditions in the WHERE clause, using logical operators like AND, refines the query results by ensuring only records that meet all specified criteria are returned, increasing the accuracy and relevance of data retrieval.

Selecting rows without a WHERE clause retrieves all rows from the database table, which can lead to performance issues and unnecessary data processing if the dataset is large. It is critical to filter data to ensure queries are efficient.

To select patient names, charges, and age for male patients, use: SELECT name, charges, age FROM hospital WHERE sex='M';

To list names of female patients in the orthopedic department, use: SELECT name FROM hospital WHERE sex='F' AND department='Orthopedic';

Indexing is crucial for optimizing query performance, especially for operations like sorting dates, as it enables faster retrieval and ordering of records by reducing the amount of data SQL engines need to process.

MySQL Worksheet - 2
 (a)  To show all information about the patients of cardiology department.
 (b) To list the names of
(c )  To list the names of 
female patients who are in 
orthopedic dept.
Ans: SELECT name FROM 
hospital WHERE sex=’F’ 
AND
Ans: SELECT name, charges, 
age FROM hospital WHERE 
sex=’M’;
(f) To count the number of 
patients with age >20.
Ans.: SELECT
(c )  To list the names of 
female patients who are in 
orthopedic dept.
Ans: SELECT name FROM 
hospital WHERE sex=’F’ 
AND
Ans: SELECT name, charges, 
age FROM hospital WHERE 
sex=’M’;
(f) To count the number of 
patients with age >20.
Ans.: SELECT

You might also like