SQL Query Practice


Problem : 1

Find all city name from USA as CountryCode and population is greater than 100000

select * from CITY
  where COUNTRYCODE = 'USA' AND POPULATION > 100000;

Select * from CITY

Select * from CITY
where ID = '1661';

Select * from CITY 
  where ID = '1661';
Select (count(CITY) - count(DISTINCT CITY))
from STATION;

SQL Query Rules for String start with , ends with or any time

^[aeiou]    // Start with a vowel
.*          // Any characters at any times
[aeiou]$    // End with a vowel

Ends With Vowels

SELECT DISTINCT city
FROM   station
WHERE city REGEXP '[aeiou]$';

Start with Vowels

SELECT DISTINCT city
FROM   station
WHERE city REGEXP '^[aeiou]';

Start with and Ends with

SELECT DISTINCT city 
FROM station 
WHERE city REGEXP '^[aeiou].*[aeiou]$';

Leave a Reply

Your email address will not be published. Required fields are marked *