Macam-Macam Operator Aritmatika
Di bawah ini adalah tabel macam-macam operator aritmatika yang dapat Anda gunakan pada Select statement di MySQL.
Operator | Deskripsi | Contoh |
---|---|---|
+ | Operator Penambahan | 20 + 10 |
- | Operator Pengurangan | 20 - 10 |
* | Operator Perkalian | 20 * 10 |
/ | Operator Pembagian | 20 / 10 |
% | Operator sisa bagi (modulus) | 20 % 10 |
Contoh Sederhana
mysql> SELECT 20+10; +-------+ | 20+10 | +-------+ | 30 | +-------+ 1 row in set (0.03 sec) mysql> SELECT 20-10; +-------+ | 20-10 | +-------+ | 10 | +-------+ 1 row in set (0.03 sec) mysql> SELECT 20*10; +-------+ | 20*10 | +-------+ | 200 | +-------+ 1 row in set (0.03 sec) mysql> SELECT 20/10; +--------+ | 20/10 | +--------+ | 2.0000 | +--------+ 1 row in set (0.00 sec) mysql> SELECT 20%10; +-------+ | 20%10 | +-------+ | 0 | +-------+ 1 row in set (0.00 sec)
Contoh Implementasi
Misalkan Anda telah membuat sebuah table "tbl_pegawai" dengan data-data sebagai berikut:
+------------+------------------+---------------+----------+------------+------------+ | id_pegawai | nama_pegawai | jenis_kelamin | gaji | alamat | departemen | +------------+------------------+---------------+----------+------------+------------+ | 1 | Nursalim | L | 1000000 | Brebes | IT | | 2 | Naura Krasiva | P | 1500000 | Tegal | FIN | | 3 | Nurul Anawariyah | P | 2000000 | Pemalang | HRD | | 4 | Achmad Fathoni | L | 3000000 | Batang | IT | | 5 | Nurul Hikmah | P | 9000000 | Pekalongan | DIR | | 6 | Iskiyati | P | 3000000 | Semarang | ACC | | 7 | Dodi Al Farizi | L | 3000000 | Kendal | FIN | | 8 | Susanto | L | 4500000 | Cilacap | MKT | | 9 | Susanti | P | 43500000 | Banyumas | MKT | | 10 | Doni Nugroho | L | 3750000 | Pemalang | HRD | +------------+------------------+---------------+----------+------------+------------+
Dari data diatas, coba Anda tampilkan nama_pegawai,gaji, gaji + 100000, gaji - 100000, gaji * 100000, dan gaji / 100000.
mysql> SELECT nama_pegawai, gaji, gaji+100000, gaji-100000, gaji*100000, gaji/100000 -> FROM tbl_pegawai; +------------------+----------+-------------+-------------+---------------+-------------+ | nama_pegawai | gaji | gaji+100000 | gaji-100000 | gaji*100000 | gaji/100000 | +------------------+----------+-------------+-------------+---------------+-------------+ | Nursalim | 1000000 | 1100000 | 900000 | 100000000000 | 10.0000 | | Naura Krasiva | 1500000 | 1600000 | 1400000 | 150000000000 | 15.0000 | | Nurul Anawariyah | 2000000 | 2100000 | 1900000 | 200000000000 | 20.0000 | | Achmad Fathoni | 3000000 | 3100000 | 2900000 | 300000000000 | 30.0000 | | Nurul Hikmah | 9000000 | 9100000 | 8900000 | 900000000000 | 90.0000 | | Iskiyati | 3000000 | 3100000 | 2900000 | 300000000000 | 30.0000 | | Dodi Al Farizi | 3000000 | 3100000 | 2900000 | 300000000000 | 30.0000 | | Susanto | 4500000 | 4600000 | 4400000 | 450000000000 | 45.0000 | | Susanti | 43500000 | 43600000 | 43400000 | 4350000000000 | 435.0000 | | Doni Nugroho | 3750000 | 3850000 | 3650000 | 375000000000 | 37.5000 | +------------------+----------+-------------+-------------+---------------+-------------+ 10 rows in set (0.00 sec)
Sekian tutorial singkat tentang Cara Menggunakan Operator Aritmatika Pada Select Statement Di MySQL. Semoga bermanfaat & Happy learning MySQL.
Salam sukses,
Nursalim.
No comments:
Post a Comment