The STATION table is described as follows:
1、Weather Observation Station 1
Query a list of CITY and STATE from the STATION table.
select CITY,STATE from STATION;
2、Weather Observation Station 3
Query a list of CITY names from STATION with even ID numbers only. You may print the results in any order, but must exclude duplicates from your answer.
select distinct CITY from STATION where mod(ID,2) = 0;
3、Weather Observation Station 4
In other words, find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
select count(CITY)-count(distinct CITY) from STATION;
4、Weather Observation Station 5
Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.
SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY),CITY LIMIT 1;SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC,CITY LIMIT 1;
5、Weather Observation Station 6
Query the list of CITY names starting with vowels (i.e., a
, e
, i
, o
, or u
) from STATION. Your result cannot contain duplicates.
SELECT distinct CITY FROM STATION WHERE CITY REGEXP '^[aeiou]';
6、Weather Observation Station 7
Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates.
SELECT distinct CITY FROM STATION WHERE CITY REGEXP '[aeiou]$';
7、Weather Observation Station 8
Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.
SELECT distinct CITY FROM STATION WHERE CITY REGEXP '^[aeiou].*[aeiou]$';
8、Weather Observation Station 9
Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates.
SELECT distinct CITY FROM STATION WHERE CITY REGEXP '^[^aeiou]';
9、Weather Observation Station 10
Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates.
SELECT distinct CITY FROM STATION WHERE CITY REGEXP '[^aeiou]$';
10、Weather Observation Station 11
Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates.
SELECT distinct CITY FROM STATION WHERE CITY REGEXP '^[^(aeiou)]|[^(aeiou)]$';
11、Weather Observation Station 12
Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates.
SELECT distinct CITY FROM STATION WHERE CITY REGEXP '^[^(aeiou)].*[^(aeiou)]$';