Rank-SQL

The STATION table is described as follows:

 

1.Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.

For example, if there are three records in the table with CITY values 'New York', 'New York', 'Bengalaru', there are 2 different city names: 'New York' and 'Bengalaru'. The query returns 1,because the total numbers of the city name - numbers of the unique city name = 3-2=1

answer: select count(city)-count(distinct(city)) from station;

 

2.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.

answer: select distinct(city) from station where regexp_like (city, '^[^aeiouAEIOU].*') or regexp_like (city, '.*[^aeiouAEIOU]$');

posted @ 2020-07-25 14:22  yaphy  阅读(93)  评论(0)    收藏  举报