2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLでレシート作成

Last updated at Posted at 2015-02-10

MySQLのレシート作成

レシートの商品と料金をテーブルに入力し小計、内税、合計を表示させる。

テーブルの作成

create table receipt(
id int(11) not null primary key auto_increment ,
Product_name varchar(45) ,
Fee int(11));

商品名 料金の入力

入力コマンド

insert into receipt(id , product_name , Fee)
values('' , 商品名 , 料金);

参照レシート

Selection_014.png

テーブルの内容

| id | Product_name | Fee |
----+-----------------------+------
| 6 | せんべい | 300 |
| 7 | ゴボウ | 500 |
| 8 | ラッキョウ | 200 |
| 9 | メガミコビン | 900 |
| 10 | ヨウセイコビン | 900 |
| 11 | アクマコビン | 900 |

Selection_015.png

表示と合計の計算

消費税率8%でそれぞれ計算する。

税込金額の計算  sum(Fee)*1.08,0
内税の計算    sum(Fee)*0.08,0)
小計の計算    sum(Fee),0)

表示コマンド

 select format(sum(Fee)*1.08,0) "税込み合計",
 format(sum(Fee)*0.08,0) "内税",
 format(sum(Fee),0) "小計" from receipt;

表示結果

| 税込み合計 | 内税 | 小計 |
-----------------+--------+--------
| 3,996 | 296 | 3,700 |

Selection_016.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?