Get the maximum price and minimum price : MAX « Aggregate Functions « SQL / MySQL






Get the maximum price and minimum price

      
mysql>
mysql> CREATE TABLE IF NOT EXISTS multimeters
    -> (
    ->   id             INT             AUTO_INCREMENT PRIMARY KEY,
    ->   model          CHAR(10)        NOT NULL,
    ->   price          DECIMAL(3,2)    NOT NULL
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO multimeters (model, price)   VALUES ("Standard", 11.75);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> INSERT INTO multimeters (model, price)   VALUES ("Super", 19.50);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> INSERT INTO multimeters (model, price)   VALUES ("DeLuxe", 24.99);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql> SELECT * FROM multimeters;
+----+----------+-------+
| id | model    | price |
+----+----------+-------+
|  1 | Standard |  9.99 |
|  2 | Super    |  9.99 |
|  3 | DeLuxe   |  9.99 |
+----+----------+-------+
3 rows in set (0.00 sec)

mysql>
mysql>
mysql>
mysql> SELECT MAX(price) AS max_price, MIN(price) AS min_price
    -> FROM multimeters;
+-----------+-----------+
| max_price | min_price |
+-----------+-----------+
|      9.99 |      9.99 |
+-----------+-----------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> # delete this sample table
mysql> DROP TABLE IF EXISTS multimeters;
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.Summarizing with MIN( ) and MAX( )
3.What are the first and last state names, lexically speaking?
4.Use the CONCAT( ) expression with MAX( ) to find the value with the largest population part:
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