PostgreSQLの中で、四則演算を使う。
https://www.postgresql.jp/docs/9.4/functions-math.html
postgresdb1=# CREATE TABLE products (
id INT,
name VARCHAR(100),
price DECIMAL(10, 2),
tax DECIMAL(10, 2),
quantity INT,
discount DECIMAL(10, 2)
);
CREATE TABLE
postgresdb1=# INSERT INTO products (id, name, price, tax, quantity, discount)
VALUES (1, 'ペン', 100.00, 10.00, 50, 5.00);
INSERT 0 1
postgresdb1=# INSERT INTO products (id, name, price, tax, quantity, discount)
VALUES (2, 'ノート', 200.00, 10.00, 10, 3.00);
INSERT 0 1
postgresdb1=# INSERT INTO products (id, name, price, tax, quantity, discount)
VALUES (3, 'ペンケース', 250.00, 10.00, 10, 3.00);
INSERT 0 1
postgresdb1=# INSERT INTO products (id, name, price, tax, quantity, discount)
VALUES (3, '消しゴム', 50.00, 10.00, 5, 8.00);
INSERT 0 1
postgresdb1=# SELECT * FROM products;
id | name | price | tax | quantity | discount
----+------------+--------+-------+----------+----------
1 | ペン | 100.00 | 10.00 | 50 | 5.00
2 | ノート | 200.00 | 10.00 | 10 | 3.00
3 | ペンケース | 250.00 | 10.00 | 10 | 3.00
3 | 消しゴム | 50.00 | 10.00 | 5 | 8.00
(4 行)
postgresdb1=# SELECT price + tax FROM products;
?column?
----------
110.00
210.00
260.00
60.00
(4 行)
postgresdb1=# SELECT price - discount FROM products;
?column?
----------
95.00
197.00
247.00
42.00
(4 行)
postgresdb1=# SELECT price * quantity FROM products;
?column?
----------
5000.00
2000.00
2500.00
250.00
(4 行)
postgresdb1=# SELECT tax / price FROM products;
?column?
------------------------
0.10000000000000000000
0.05000000000000000000
0.04000000000000000000
0.20000000000000000000
(4 行)
postgresdb1=#こんな感じで使える。
ただ、カラム名がないので"?column?"と出てる。