Olawale Ahmed Alamu
1 min readNov 18, 2022

--

SQL Daily Practice — Day 13

Hello, Connections, Data Professionals and SQL Enthusiasts.

Here comes #day13 of our SQL daily practice on SQL-practice-dot-com.

Follow Olawale Ahmed Alamu and #sqldailyupdates for #day1 to #day12 and daily updates.

Today, we are looking at SQL COUNT(column_name) function.

SQL COUNT(column_name) function is used to get the total number of records in a column that is not NULL.

QUESTION: Show the total number of admissions for patient_id: 579

PROBLEM ANALYSIS: We are expected to output the total count of when patient_id: 579 was admitted.

The admissions table has the following columns:
patient_id (INT),
admission_date (DATE),
discharge_date (DATE),
diagnosis (TEXT),
attending_physician_id (INT),
pk_admissions

SOLUTION: We write a SELECT COUNT(patient_id) with a WHERE clause to filter for only patient_id: 579.

SQL SCRIPT:
-- -- -- -- -- -- — 
SELECT
patient_id,
COUNT(patient_id) AS total_admissions
FROM admissions
WHERE patient_id = 579
-- -- -- -- -- -- —

Screenshot image of the SQL Script and output in the attached below:

#sql #health #databases #dataanalytics

--

--

Olawale Ahmed Alamu

CS Grad | Power BI | Microsoft Excel | Learning and Teaching SQL Daily