DEV Community

Tharunya K R
Tharunya K R

Posted on

Database Problems

Query all columns for a city in CITY with the ID 1661.

SELECT * FROM CITY WHERE ID=1661;
Meaning : Return all columns from CITY table where ID is equal to 1661

Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA.

SELECT * FROM CITY WHERE CountryCode = 'USA' AND Population >100000 ;
Meaning : Return all columns from CITY table where CountryCode is USA and population is greater than 100000

Query all attributes of every Japanese city in the City table. The COUNTRYCODE for Japan is JPN.

SELECT * FROM CITY WHERE CountryCode='JPN';
Meaning : Return all columns from CITY table where CountryCode is JPN

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) AS difference FROM STATION;
Meaning : Return the difference between total number of city entries and unique city entries from the STATION table

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;
Meaning : Return only the NAME column of cities from CITY table where CountryCode is USA and population is greater than 120000

Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.

SELECT NAME FROM CITY WHERE COUNTRYCODE = 'JPN';
Meaning : Return only the NAME column of cities from CITY table where CountryCode is JPN

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 NOT LIKE 'A%' AND CITY NOT LIKE 'E%' AND CITY NOT LIKE 'I%' AND CITY NOT LIKE 'O%' AND CITY NOT LIKE 'U%';
Meaning : Return unique city names from STATION table where the city name not start with a vowel

Query all columns (attributes) for every row in the CITY table.

SELECT * FROM CITY;
Meaning : Return all columns and all rows from the CITY table

Query a list of CITY and STATE from the STATION table.

SELECT CITY , STATE FROM STATION;
Meaning : Return only the CITY and STATE columns from the STATION table

Top comments (0)