blog.itcode.devblog.itcode.dev

[Programmers / MySQL] Level 1 Find the Maximum Value (59415)

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 Find the Maximum Value (59415)

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:41:43
Programmers

시리즈 모아보기

Programmers

15 / 78
RankLanguage Used
Level 1

🖼️ JAVA

🔗 Find the Maximum Value

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 finds when the most recently admitted animal came in.

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 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.

TIME
2013-11-18 17:03:00
  • The column name (labeled "TIME" in the example above) does not need to match exactly.

Query ANIMAL_INS, and retrieve only the single topmost record with the most recent DATETIME.

In MySQL, LIMIT 1 is used to retrieve only the single topmost record.

SQL

SELECT DATETIME FROM ANIMAL_INS ORDER BY DATETIME DESC 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