blog.itcode.devblog.itcode.dev

[Programmers / MySQL] Level 1 Finding Sick Animals (59036)

The ANIMAL_INS table is a table containing information about animals that have entered an animal shelter. The ANIMAL_INS table structure is as follows, where ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, and SEX_UPON_INTAKE represent the animal's ID, species, intake date, condition at intake, name, and sex/neuter status, respectively.

[Programmers / MySQL] Level 1 Finding Sick Animals (59036)

The ANIMAL_INS table is a table containing information about animals that have entered an animal shelter. The ANIMAL_INS table structure is as follows, where ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, and SEX_UPON_INTAKE represent the animal's ID, species, intake date, condition at intake, name, and sex/neuter status, respectively.
RWB0104
@RWBwritten at 2021-12-15 13:50:59
Programmers

시리즈 모아보기

Programmers

25 / 78
RankLanguage Used
Level 1

🖼️ MySQL

🔗 Finding Sick Animals

The ANIMAL_INS table is a table containing information about animals that have entered an animal shelter. The ANIMAL_INS table structure is as follows, where ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, and SEX_UPON_INTAKE represent the animal's ID, species, intake date, condition at intake, name, and sex/neuter status, respectively.

NAMETYPENULLABLE
ANIMAL_IDVARCHAR(N)FALSE
ANIMAL_TYPEVARCHAR(N)FALSE
DATETIMEDATETIMEFALSE
INTAKE_CONDITIONVARCHAR(N)FALSE
NAMEVARCHAR(N)TRUE
SEX_UPON_INTAKEVARCHAR(N)FALSE

Write a SQL statement to retrieve the ID and name of sick animals among the animals that entered the shelter. Sort the result by ID.

For instance, if the ANIMAL_INS table looks like this:

ANIMAL_IDANIMAL_TYPEDATETIMEINTAKE_CONDITIONNAMESEX_UPON_INTAKE
A365172Dog2014-08-26 12:53:00NormalDiabloNeutered Male
A367012Dog2015-09-16 09:06:00SickMillerNeutered Male
A365302Dog2017-01-08 16:34:00AgedMinnieSpayed Female
A381217Dog2017-07-08 09:41:00SickCherokeeNeutered Male

Among these, the sick animals are Miller and Cherokee. So running the SQL should produce the following:

ANIMAL_IDNAME
A367012Miller
A381217Cherokee

Retrieve the ANIMAL_ID and NAME of sick animals whose INTAKE_CONDITION is marked as Sick. Sort the results in ascending order by ANIMAL_ID.

SQL

SELECT ANIMAL_ID, NAME FROM ANIMAL_INS WHERE INTAKE_CONDITION = 'Sick' ORDER BY ANIMAL_ID;
# Programmers# Algorithm# SQL# Level 1
ship
blog.itcode.dev

Notes from the π-th Alpaca

7.0.1
Developed by RWB since 2021.057th upgraded at 2026.08