The expression in the select list subtracts the Reserved value from the total : Simple Select « Select Clause « SQL / MySQL






The expression in the select list subtracts the Reserved value from the total

       
mysql>
mysql>
mysql> CREATE TABLE CDs
    -> (
    ->     CDID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ->     CDName VARCHAR(50) NOT NULL,
    ->     InStock SMALLINT UNSIGNED NOT NULL,
    ->     OnOrder SMALLINT UNSIGNED NOT NULL,
    ->     Reserved SMALLINT UNSIGNED NOT NULL,
    ->     Department ENUM('Classical', 'Popular') NOT NULL,
    ->     Category VARCHAR(20) NOT NULL,
    ->     RowUpdate TIMESTAMP NOT NULL
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> INSERT INTO CDs (CDName, InStock, OnOrder, Reserved, Department, Category) VALUES
    -> ('Xml', 10, 5, 3, 'Popular', 'Rock'),
    -> ('Java', 10, 5, 3, 'Classical', 'Opera'),
    -> ('SQL', 17, 4, 1, 'Popular', 'Jazz'),
    -> ('MySQL', 9, 4, 2, 'Classical', 'Dance'),
    -> ('CSS', 24, 2, 5, 'Classical', 'General'),
    -> ('HTML', 16, 6, 8, 'Classical', 'Vocal'),
    -> ('Oracle', 2, 25, 6, 'Popular', 'Blues'),
    -> ('Javascript', 32, 3, 10, 'Popular', 'Jazz'),
    -> ('Data type', 12, 15, 13, 'Popular', 'Country'),
    -> ('Flash', 5, 20, 10, 'Popular', 'New Age'),
    -> ('Ajax', 24, 11, 14, 'Popular', 'New Age'),
    -> ('Photoshop', 42, 17, 17, 'Classical', 'General'),
    -> ('Word', 25, 44, 28, 'Classical', 'Dance'),
    -> ('iPhone', 32, 15, 12, 'Classical', 'General'),
    -> ('MacBook', 20, 10, 5, 'Classical', 'Opera'),
    -> ('Linux', 23, 12, 8, 'Classical', 'General'),
    -> ('Shell', 23, 10, 17, 'Popular', 'Country'),
    -> ('Pascal', 18, 20, 10, 'Popular', 'Jazz'),
    -> ('Ruby', 22, 5, 7, 'Popular', 'Blues'),
    -> ('Sql Server', 28, 17, 16, 'Classical', 'General'),
    -> ('Opera', 10, 35, 12, 'Classical', 'Opera'),
    -> ('Safari', 15, 30, 14, 'Popular', 'Blues'),
    -> ('C', 42, 0, 8, 'Popular', 'Blues'),
    -> ('C++', 16, 8, 8, 'Classical', 'General');
Query OK, 24 rows affected (0.00 sec)
Records: 24  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> SELECT CDName, InStock+OnOrder-Reserved AS Total
    -> FROM CDs;
+------------+-------+
| CDName     | Total |
+------------+-------+
| Xml        |    12 |
| Java       |    12 |
| SQL        |    20 |
| MySQL      |    11 |
| CSS        |    21 |
| HTML       |    14 |
| Oracle     |    21 |
| Javascript |    25 |
| Data type  |    14 |
| Flash      |    15 |
| Ajax       |    21 |
| Photoshop  |    42 |
| Word       |    41 |
| iPhone     |    35 |
| MacBook    |    25 |
| Linux      |    27 |
| Shell      |    16 |
| Pascal     |    28 |
| Ruby       |    20 |
| Sql Server |    29 |
| Opera      |    33 |
| Safari     |    31 |
| C          |    34 |
| C++        |    16 |
+------------+-------+
24 rows in set (0.00 sec)

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

mysql>

   
    
    
    
    
    
    
  








Related examples in the same category

1.Explain select command
2.Get the number, name, and date of birth of each player resident in Stratford; sort the result in alphabetical
3.Do math calculation with select
4.SELECT statement includes three select list elements
5.Select rows
6.Removing duplicates and selecting only the unique combinations of values in the specified columns
7.Display the names of only those authors whose surname starts with one of the letters L through Z:
8.Determines all employees whose names contain the sequence of letters er.
9.Use a wildcard (*) to return all the fields
10.Using mysql as a Calculator
11.Identifying What Values to Display
12.Using the aliases p1 and p2 to refer to the book table different ways