Show all those pets born between 1999 and 2001 inclusive. The pet's id together with its name, type, breed and year of birth is required. The report should list the pets in order of age, ie the oldest first.
时间: 2024-02-24 15:00:35 浏览: 23
Assuming you have a `pets` table with fields as follows:
`pets` table:
- `pet_id` (primary key)
- `name`
- `type`
- `breed`
- `birthdate` (in the format of YYYY-MM-DD)
You can use the following SQL query to show all pets born between 1999 and 2001 inclusive, in order of age:
```
SELECT pet_id, name, type, breed, YEAR(birthdate) as birthyear
FROM pets
WHERE birthdate BETWEEN '1999-01-01' AND '2001-12-31'
ORDER BY birthdate;
```
This query selects the `pet_id`, `name`, `type`, `breed`, and `birthdate` fields from the `pets` table. The `YEAR` function is used to extract the year from the `birthdate` field. The `WHERE` clause is used to filter the results to only include pets born between 1999 and 2001 inclusive. Finally, the `ORDER BY` clause is used to sort the results in ascending order of `birthdate`, which means the oldest pets will appear first in the result set.