HackerRank数据库题目练习(2)
HackerRank
最近在瘋狂刷題,推薦一個刷題網站https://www.hackerrank.com/dashboard
題目1、
Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates.
Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
-- Query the list of *CITY* names from **STATION** that *do not start* with vowels. Your result cannot contain duplicates. 方法一: selectdistinct city from station wherecity not like 'A%' andcity not like 'O%' andcity not like 'E%' andcity not like 'I%' andcity not like 'U%' 方法二: -- 將^放在封閉的括號中意味著與將其放在括號之外完全不同。將其放在方括號內可使其匹配所有字符,但括號內的字符除外。因此,我們可以寫[^ aeiou]而不是寫[bcdfghjklmnpqrstvwxyz] SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[^aeiou]';方法三: select DISTINCT city FROM station WHERE substr(city, 1, 1) NOT IN ('a','e','i','o','u');題目2、
Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA.
The CITY table is described as follows:
-- Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA. select* fromCITY wherecountrycode='USA' and population>100000題目3、
Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.
The CITY table is described as follows:
Current Buffer (saved locally, editable)
-- Query the **NAME** field for all American cities in the **CITY** table with populations larger than `120000`. The *CountryCode* for America is `USA`. select `NAME` from CITY where CountryCode='USA' and population>120000題目4、
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.
The STATION table is described as follows:
總結
以上是生活随笔為你收集整理的HackerRank数据库题目练习(2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HackerRank Lists
- 下一篇: CF617E XOR and Favor