blog.itcode.devblog.itcode.dev

[Programmers / MySQL] Level 1 IDs of Animals with Names (59407)

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 IDs of Animals with Names (59407)

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:21:06
Programmers

시리즈 모아보기

Programmers

23 / 78
RankLanguage Used
Level 1

🖼️ MySQL

🔗 IDs of Animals with Names

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 IDs of animals that have a name among the animals that entered the shelter. The result must be sorted in ascending order by ID.

For instance, if the ANIMAL_INS table looks like this:

ANIMAL_IDANIMAL_TYPEDATETIMEINTAKE_CONDITIONNAMESEX_UPON_INTAKE
A434523Cat2015-11-20 14:18:00NormalNULLSpayed Female
A562649Dog2014-03-20 18:06:00SickNULLSpayed Female
A524634Dog2015-01-02 18:54:00Normal*BelleIntact Female
A465637Dog2017-06-04 08:17:00Injured*CommanderNeutered Male

The IDs of animals with names are A524634 and A465637. Therefore, running the SQL should output the following:

ANIMAL_ID
A465637
A524634

Sort the animals that have a NAME in ascending order by ANIMAL_ID.

SQL

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