Contents

Finding Sick Animals (with.MySQL)

   Nov 13, 2024     1 min read

This is an article about finding sick animals (with.MySQL).

I want to solve the coding test problem, find out how to solve it differently from the retrospective of the problem I solved, and get to know.

Let’s get to the problem first.

Problem

Please write a SQL statement that looks up the ID and name of sick animal 1 among the animals that came into the animal shelter.

At this time, please check the results in the order of ID.

Problem Description

The ANIMAL_INS table is a table that contains information about animals that have entered the animal shelter.

ANIMAL_INS table structures are as follows: ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE indicate the animal’s ID, species, start date of protection, status, name, gender, and neutralization at the start of protection, respectively.

ANIMAL_INS table

NAMETYPENULLABLE
ANIMAL_IDVARCHAR(N)FALSE
ANIMAL_TYPEVARCHAR(N)FALSE
DATETIMEDATETIMEFALSE
INTAKE_CONDITIONVARCHAR(N)FALSE
NAMEVARCHAR(N)TRUE
SEX_UPON_INTAKEVARCHAR(N)FALSE

problem solving

SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
WHERE INTAKE_CONDITION = "Sick"
ORDER BY ANIMAL_ID;

Solution Description

From the ANIMAL_INS table required in the problem, the IDs and names of all animals in sick condition were printed, and sorted in ascending order of IDs.