blog.itcode.devblog.itcode.dev

[Programmers / MySQL] Level 1 Top N Records (59405)

The ANIMAL_INS table contains information about animals that entered the 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 Top N Records (59405)

The ANIMAL_INS table contains information about animals that entered the 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-16 11:06:17
Programmers

시리즈 모아보기

Programmers

36 / 78
RankLanguage Used
Level 1

🖼️ MySQL

🔗 Top N Records

The ANIMAL_INS table contains information about animals that entered the 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 that retrieves the name of the animal that was admitted to the shelter first.

For example, if the ANIMAL_INS table is as follows:

ANIMAL_IDANIMAL_TYPEDATETIMEINTAKE_CONDITIONNAMESEX_UPON_INTAKE
A399552Dog2013-10-14 15:38:00NormalJackNeutered Male
A379998Dog2013-10-23 11:42:00NormalDiscipleIntact Male
A370852Dog2013-11-03 15:04:00NormalKatieSpayed Female
A403564Dog2013-11-18 17:03:00NormalAnnaSpayed Female

The animal admitted to the shelter first among these is Jack. Therefore, running the SQL statement should produce the following result:

NAME
Jack

※ Test cases are given such that there is only ever one animal that was admitted first.

Return the NAME of the animal that was admitted first.

SQL

SELECT NAME FROM ANIMAL_INS ORDER BY DATETIME ASC LIMIT 1;
# 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