blog.itcode.devblog.itcode.dev

[Programmers / MySQL] Level 1 IDs of Animals Without a Name (59039)

The ANIMAL_INS table holds information about animals that have come into 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 IDs of Animals Without a Name (59039)

The ANIMAL_INS table holds information about animals that have come into 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-14 16:44:37
Programmers

시리즈 모아보기

Programmers

16 / 78
RankLanguage Used
Level 1

🖼️ MySQL

🔗 IDs of Animals Without a Name

The ANIMAL_INS table holds information about animals that have come into 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 an SQL statement that retrieves the IDs of animals that were admitted to the shelter without a name. The IDs should be sorted in ascending order.

For example, if the ANIMAL_INS table is as follows

ANIMAL_IDANIMAL_TYPEDATETIMEINTAKE_CONDITIONNAMESEX_UPON_INTAKE
A368930Dog2014-06-08 13:20:00NormalNULLSpayed Female
A524634Dog2015-01-02 18:54:00Normal*BelleIntact Female
A465637Dog2017-06-04 08:17:00Injured*CommanderNeutered Male

The animal that was admitted most recently is Anna, and Anna was admitted at 2013-11-18 17:03:00. So running the SQL statement should produce the following.

ANIMAL_ID
A368930

Query ANIMAL_INS, retrieving records where NAME is null, ordered by ANIMAL_ID. From those records, retrieve only ANIMAL_ID.

SQL

SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NULL 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