Use the CONCAT( ) expression with MAX( ) to find the value with the largest population part: : MAX « Aggregate Functions « SQL / MySQL






Use the CONCAT( ) expression with MAX( ) to find the value with the largest population part:

       
mysql>
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> SELECT MAX(CONCAT(LPAD(pop,8,' '),name)) FROM states;
+-----------------------------------+
| MAX(CONCAT(LPAD(pop,8,' '),name)) |
+-----------------------------------+
| NULL                              |
+-----------------------------------+
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.Calculate the maximum value by using the MAX() function: MAX()
2.Get the maximum price and minimum price
3.Summarizing with MIN( ) and MAX( )
4.What are the first and last state names, lexically speaking?
5.Finding Values Associated with Minimum and Maximum Values
6.Determine the population range:
7.To obtain the state name associated with the maximum population
8.Returning the Maximum Value with MAX()
9.Finds the size of the largest message sent between each pair of sender and recipient values listed