SQL Daily Practice — Day 12
Hello, Connections, Data Professionals and SQL Enthusiasts.
It is the 12th day of our SQL daily practice on SQL-practice-dot-com.
Follow Olawale Ahmed Alamu and #sqldailyupdates for #day1 to #day11 and daily updates.
Today, we are using the WHERE clause with the comparison operator '='.
The different comparison operators that can be used with the WHERE clause are <, >, <=, >=, = and <>.
QUESTION: Show all the columns from admissions where the patient was admitted and discharged on the same day.
PROBLEM ANALYSIS: We are expected to output the records for all patients that were admitted and discharged on the same day.
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 an SQL * SELECT statement with a WHERE clause of admission_date being equal to discharge_date
SQL SCRIPT:
-- -- -- -- -- -- —
SELECT *
FROM admissions
WHERE admission_date = discharge_date;
-- -- -- -- -- -- —
Screenshot image of the SQL Script and output attached below:
#sql #health #databases #dataanalytics