CA 21 - Basic Select SQL Queries
1.Revising the Select Query I:
Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.
SELECT id,name,countrycode,district,population from city where population > 100000 AND countrycode='USA';
2.Revising the Select Query II
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 population > 120000 and countrycode='USA';
3.Select All
Query all columns (attributes) for every row in the CITY table.
select * from city;
4.Select By ID
Query all columns for a city in CITY with the ID
1661.SELECT * from city where ID=1661;
5.Japanese Cities' Attributes
Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is
JPN.SELECT * from city where countrycode='JPN';
6.Japanese Cities' Names
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';
7.Weather Observation Station 1
Query a list of CITY and STATE from the STATION table.
select city ,state from station;
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 Not like 'A%' and city Not like 'E%' and city Not like 'I%' and
city Not like 'O%' and city not like 'U%';
9.Weather Observation Station 4Find 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;
Comments
Post a Comment