Calculation : Select « Select Clause « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
PostgreSQL
MySQL Tutorial
SQL / MySQL » Select Clause » Select 
Calculation
       
mysql>
mysql> CREATE TABLE IF NOT EXISTS wines
    -> (
    ->   id             INT     AUTO_INCREMENT  PRIMARY KEY,
    ->   type           CHAR(10)        NOT NULL,
    ->   price          DECIMAL(6,2)    NOT NULL,
    ->   quantity       INT             DEFAULT 0
    -> );
Query OK, rows affected (0.00 sec)

mysql>
mysql> INSERT INTO wines (type, price, quantity)   VALUES ("Red"10.0012);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO wines (type, price, quantity)   VALUES ("White"9.0012);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO wines (type, price, quantity)   VALUES ("Rose"8.006);
Query OK, row affected (0.00 sec)

mysql>
mysql> SELECT   type,
    ->  price AS bottle,
    ->  quantity AS qty,
    ->  price * quantity AS subtotal,
    ->  (price * quantity(100AS tax,
    ->  (price * quantity+
    ->    (price * quantity(100AS total
    -> FROM wines ;
+-------+--------+------+----------+----------+------------+
| type  | bottle | qty  | subtotal | tax      | total      |
+-------+--------+------+----------+----------+------------+
| Red   |  10.00 |   12 |   120.00 7.200000 127.200000 |
| White |   9.00 |   12 |   108.00 6.480000 114.480000 |
| Rose  |   8.00 |    |    48.00 2.880000 |  50.880000 |
+-------+--------+------+----------+----------+------------+
rows in set (0.00 sec)

mysql>
mysql> # delete this sample table
mysql> DROP TABLE wines;
Query OK, rows affected (0.00 sec)

   
    
    
    
    
    
    
  
Related examples in the same category
1.Define and use variable in select clause
2.Use defined variable in new select clause
3.Select clause with condition
4.Choose specific columns
5.Reference column in select command
6.Performing Mathematics
7.Simple Retrieval:Returning Multiple Columns
8.Simple Retrieval:Returning a Single Column
9.Simple Retrieval: Returning All Columns
10.Performing a Single Row INSERT
11.Retrieve all columns in a table
12.Using constant string value as comment message for aggregate function
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.