blog.itcode.devblog.itcode.dev

[Programmers / MySQL] Level 2 Find Lucy and Ella (59046)

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

[Programmers / MySQL] Level 2 Find Lucy and Ella (59046)

The ANIMAL_INS table holds information about animals that came into the animal shelter. The ANIMAL_INS table structure is as follows, where ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, and SEX_UPON_INTAKE respectively represent the animal's ID, species, intake date, condition at intake, name, and sex/neuter status.
RWB0104
@RWBwritten at 2021-12-28 08:38:16
Programmers

시리즈 모아보기

Programmers

75 / 78
RankLanguage Used
Level 1

🖼️ MySQL

🔗 Find Lucy and Ella

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

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 ID, name, and sex/neuter status of animals that came into the animal shelter with the names Lucy, Ella, Pickle, Rogan, Sabrina, or Mitty.

Please return the result ordered by ID. For example, if the ANIMAL_INS table is as follows

ANIMAL_IDANIMAL_TYPEDATETIMEINTAKE_CONDITIONNAMESEX_UPON_INTAKE
A373219Cat2014-07-29 11:43:00NormalEllaSpayed Female
A377750Dog2017-10-25 17:17:00NormalLucySpayed Female
A353259Dog2016-05-08 12:57:00InjuredBjNeutered Male
A354540Cat2014-12-11 11:48:00NormalTuxNeutered Male
A354597Cat2014-05-02 12:16:00NormalArielSpayed Female

Running the SQL statement should produce the following.

ANIMAL_IDNAMESEX_UPON_INTAKE
A373219EllaSpayed Female
A377750LucySpayed Female
  1. Retrieve animals whose NAME is Lucy, Ella, Pickle, Rogan, Sabrina, or Mitty.
  2. Retrieve ANIMAL_ID, NAME, and SEX_UPON_INTAKE.
  3. Retrieve them ordered alphabetically by ANIMAL_ID.

Using IN, you can retrieve data containing multiple elements at once.

SQL

SELECT ANIMAL_ID, NAME, SEX_UPON_INTAKE FROM ANIMAL_INS WHERE NAME IN ('Lucy', 'Ella', 'Pickle', 'Rogan', 'Sabrina', 'Mitty') ORDER BY ANIMAL_ID;
# Programmers# Algorithm# SQL# Level 2
ship
blog.itcode.dev

Notes from the π-th Alpaca

7.0.1
Developed by RWB since 2021.057th upgraded at 2026.08