SQL Daily Practice — Day 14

Olawale Ahmed Alamu
1 min readDec 3, 2022

Hello, Connections, Data Professionals and SQL Enthusiasts.

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

Follow Olawale Ahmed Alamu and #sqldailyupdates for #day1 to #day13 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 CODE:
— — — — — —
SELECT
patient_id,
COUNT(patient_id) AS total_admissions
FROM admissions
WHERE patient_id = 579
— — — — — —

A screenshot of the SQL Script and output is attached in the image below:

#sql #health #databases #dataanalytics

--

--

Olawale Ahmed Alamu

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