How many states did the United States consist of at the beginning of the 20th century? : COUNT « Aggregate Functions « SQL / MySQL






How many states did the United States consist of at the beginning of the 20th century?

       
mysql> CREATE TABLE states
    -> (
    ->  name            VARCHAR(30) NOT NULL,   # state name
    ->  abbrev          CHAR(2) NOT NULL,               # 2-char abbreviation
    ->  statehood       DATE,                                   # date of entry into the Union
    ->  pop                     BIGINT,                                 # population as of 4/1990
    ->  PRIMARY KEY (abbrev)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> insert into states(name, abbrev, statehood, pop)values
    -> ("Alabama","AL","1819-12-14",4040587),
    -> ("Alaska","AK","1959-01-03",550043),
    -> ("Arizona","AZ","1912-02-14",3665228),
    -> ("Arkansas","AR","1836-6-15",2350725),
    -> ("California","CA","1850-9-9",29760021),
    -> ("Colorado","CO","1876-8-1",3294394),
    -> ("Connecticut","CT","1788-1-9",3287116),
    -> ("Delaware","DE","1787-12-7",666168),
    -> ("Florida","FL","1845-3-3",12937926),
    -> ("Georgia","GA","1788-1-2",6478216),
    -> ("Hawaii","HI","1959-08-21",1108229),
    -> ("Idaho","ID","1890-7-3",1006749),
    -> ("Illinois","IL","1818-12-3",11430602),
    -> ("Indiana","IN","1816-12-11",5544159),
    -> ("Iowa","IA","1846-12-28",2776755),
    -> ("Kansas","KS","1861-1-29",2477574),
    -> ("Kentucky","KY","1792-6-1",3685296),
    -> ("Louisiana","LA","1812-4-30",4219973),
    -> ("Maine","ME","1820-3-15",1227928),
    -> ("Maryland","MD","1788-4-28",4781468),
    -> ("Massachusetts","MA","1788-2-6",6016425),
    -> ("Michigan","MI","1837-1-26",9295297),
    -> ("Minnesota","MN","1858-5-11",4375099);
Query OK, 23 rows affected (0.00 sec)
Records: 23  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> SELECT COUNT(*) FROM states WHERE statehood < '1900-01-01';
+----------+
| COUNT(*) |
+----------+
|       20 |
+----------+
1 row in set (0.00 sec)

mysql>
mysql> drop table states;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
    
  








Related examples in the same category

1.COUNT([DISTINCT] { | *})
2.Get the number of items for each type of wood
3.Get the number of woods for each type of item
4.Counting
5.How many times did drivers travel more than 200 miles in a day?
6.COUNT and GROUP BY
7.Count by group
8.COUNT(expr) doesn't count NULL values is useful when producing multiple counts from the same set of values.
9.The different forms of COUNT( ) can be very useful for counting missing values
10.Put the COUNT( ) expression in a HAVING clause instead.
11.Tracking Down Duplicates
12.Queries counting duplicate records have the following form
13.Counting and Identifying Duplicates
14.Count number of rows containing duplicated names
15.To see which names are duplicated in the cat_mailing table, use a summary query that displays the non-unique v
16.Eliminating Duplicates from a Query Result
17.Removing Duplicates of a Particular Row
18.Count duplicate records
19.How many days did Suzi drive?
20.How many messages were sent by each message sender
21.Or to count weekend versus weekday trips
22.Count each value and see which one is most common
23.Generating Frequency Distributions
24.Relative frequency distributions
25.Counting Missing Values
26.Count them directly using SUM(ISNULL(score)).
27.Count the total number of rows
28.Categorizing Non-Categorical Data
29.Total number of the table vs unique values count
30.To produce a count-per-author summary that includes even authors with no books in the book table, use a LEFT J