[Programmers / MySQL] Level 1 Finding Young Animals (59037)
[Programmers / MySQL] Level 1 Finding Young Animals (59037)
| Rank | Language Used |
|---|---|
| Level 1 | 🖼️ MySQL |
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.
| NAME | TYPE | NULLABLE |
|---|---|---|
| ANIMAL_ID | VARCHAR(N) | FALSE |
| ANIMAL_TYPE | VARCHAR(N) | FALSE |
| DATETIME | DATETIME | FALSE |
| INTAKE_CONDITION | VARCHAR(N) | FALSE |
| NAME | VARCHAR(N) | TRUE |
| SEX_UPON_INTAKE | VARCHAR(N) | FALSE |
Write a SQL statement to retrieve the ID and name of young animals among the animals that entered the shelter. Sort the result by ID.
For instance, if the ANIMAL_INS table looks like this:
| ANIMAL_ID | ANIMAL_TYPE | DATETIME | INTAKE_CONDITION | NAME | SEX_UPON_INTAKE |
|---|---|---|---|---|---|
| A365172 | Dog | 2014-08-26 12:53:00 | Normal | Diablo | Neutered Male |
| A367012 | Dog | 2015-09-16 09:06:00 | Sick | Miller | Neutered Male |
| A365302 | Dog | 2017-01-08 16:34:00 | Aged | Minnie | Spayed Female |
| A381217 | Dog | 2017-07-08 09:41:00 | Sick | Cherokee | Neutered Male |
Among these, the young animals are Diablo, Miller, and Cherokee. So running the SQL should produce the following:
| ANIMAL_ID | NAME |
|---|---|
| A365172 | Diablo |
| A367012 | Miller |
| A381217 | Cheroke |
Retrieve the ANIMAL_ID and NAME of young animals whose INTAKE_CONDITION is not Aged. Sort the results in ascending order by ANIMAL_ID.
SQL
SELECT ANIMAL_ID, NAME FROM ANIMAL_INS WHERE INTAKE_CONDITION != 'Aged' ORDER BY ANIMAL_ID;
