Thursday, November 16, 2017

PERINTAH FUNGSI SUM, COUNT, MAX, MIN, & AVG PADA MYSQL DENGAN CMD & Command Line Linux

Gak usah basa basi ya.... :D
Saya menggunakan command line di Linux, tapi jangan kuatir perintahnya gak berdeda dengan CMD di Windows. Hanya saja untuk mengaktifkan XAMPP Linux ya lewat command line.

Baca juga perintah dasar mysql cmd.

Ini dia.













Yah itu aja dah...
Semoga bermanfaat.

Salomo Silaban


salomo@silaban-X455LAB:~$ sudo /opt/lampp/lampp start
[sudo] password for salomo: 
Starting XAMPP for Linux 7.0.24-0...
XAMPP: Starting Apache...already running.
XAMPP: Starting MySQL...already running.
salomo@silaban-X455LAB:~$ /opt/lampp/bin/mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.1.28-MariaDB Source distribution

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> Create database Akademik;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> Use Akademik;
Database changed
MariaDB [Akademik]> Create table Tabel_MK (Kode_MK char(17),
    -> Nama_MK char (30),
    -> SKS int (1),
    -> Semester int (1));
Query OK, 0 rows affected (0.38 sec)

MariaDB [Akademik]> Show databases;
+-----------------------+
| Database              |
+-----------------------+
| Akademik              |
| catatan               |
| information_schema    |
| latihan_android       |
| mysql                 |
| pendaftaran_mahasiswa |
| performance_schema    |
| phpmyadmin            |
| test                  |
| wordpress             |
+-----------------------+
10 rows in set (0.00 sec)

MariaDB [Akademik]> desc Tabel_MK;
+----------+----------+------+-----+---------+-------+
| Field    | Type     | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| Kode_MK  | char(17) | YES  |     | NULL    |       |
| Nama_MK  | char(30) | YES  |     | NULL    |       |
| SKS      | int(1)   | YES  |     | NULL    |       |
| Semester | int(1)   | YES  |     | NULL    |       |
+----------+----------+------+-----+---------+-------+
4 rows in set (0.10 sec)

MariaDB [Akademik]> Insert into Tabel_MK values ('14213201/15916313','Basis Data','2','3'),
    -> ('14213202/15916413','Statistik Probabilitas','2','3'), 
    -> ('14213203/15916324','Matematika Diskrit','2','3'), 
    -> ('14213206/15916354','Teori Graph','2','3'), 
    -> ('14213404/15916343','Sistem Operasi','4','3'), 
    -> ('14213405/15916364','Rekayasa Perangkat Lunak','4','3'),
    -> ('142AI2208/14784422','Arsitektur & Organisasi Komputer','2','2'),
    -> ('142AP2210/14783053','Pendidikan Kewarganegaraan','2','2'),
    -> ('142I2202/14784082','Logika Informatika','2','2'),
    -> ('142I2403/14784082','Jaringan Komputer 1','4','2'),
    -> ('142I2404/14783364','Struktur Data','4','2'),
    -> ('142S2201/14838025','Praktikum Struktur Data','2','2'),
    -> ('142AI12025/14498183','Pengantar Teknologi Informasi','2','1'),
    -> ('142AP1204/14315645','Pendidikan Agama','2','1'),
    -> ('142I1402/14530654','Konsep Bahasa Pemograman','2','1'),
    -> ('142I1204/14266845','Algoritma & Pemograman','4','1'),
    -> ('142I1403/14225363','Kalkulus','4','1'),
    -> ('142I1405/14478324','Pengantar Basis Data','4','1'),
    -> ('142S1202/14547914','Praktikum Pemograman','2','1'),
    -> ('142S1201/14468603','Praktikum Internet','2','1');
Query OK, 20 rows affected, 5 warnings (0.18 sec)
Records: 20  Duplicates: 0  Warnings: 5

MariaDB [Akademik]> Select*from Tabel_MK;
+-------------------+--------------------------------+------+----------+
| Kode_MK           | Nama_MK                        | SKS  | Semester |
+-------------------+--------------------------------+------+----------+
| 14213201/15916313 | Basis Data                     |    2 |        3 |
| 14213202/15916413 | Statistik Probabilitas         |    2 |        3 |
| 14213203/15916324 | Matematika Diskrit             |    2 |        3 |
| 14213206/15916354 | Teori Graph                    |    2 |        3 |
| 14213404/15916343 | Sistem Operasi                 |    4 |        3 |
| 14213405/15916364 | Rekayasa Perangkat Lunak       |    4 |        3 |
| 142AI2208/1478442 | Arsitektur & Organisasi Komput |    2 |        2 |
| 142AP2210/1478305 | Pendidikan Kewarganegaraan     |    2 |        2 |
| 142I2202/14784082 | Logika Informatika             |    2 |        2 |
| 142I2403/14784082 | Jaringan Komputer 1            |    4 |        2 |
| 142I2404/14783364 | Struktur Data                  |    4 |        2 |
| 142S2201/14838025 | Praktikum Struktur Data        |    2 |        2 |
| 142AI12025/144981 | Pengantar Teknologi Informasi  |    2 |        1 |
| 142AP1204/1431564 | Pendidikan Agama               |    2 |        1 |
| 142I1402/14530654 | Konsep Bahasa Pemograman       |    2 |        1 |
| 142I1204/14266845 | Algoritma & Pemograman         |    4 |        1 |
| 142I1403/14225363 | Kalkulus                       |    4 |        1 |
| 142I1405/14478324 | Pengantar Basis Data           |    4 |        1 |
| 142S1202/14547914 | Praktikum Pemograman           |    2 |        1 |
| 142S1201/14468603 | Praktikum Internet             |    2 |        1 |
+-------------------+--------------------------------+------+----------+
20 rows in set (0.00 sec)

MariaDB [Akademik]> Select SUM(SKS) as Total_SKS from Tabel_MK;
+-----------+
| Total_SKS |
+-----------+
|        54 |
+-----------+
1 row in set (0.05 sec)


MariaDB [Akademik]> Select SUM(SKS) as Total_SKS_Semester_1 from Tabel_MK where Semester='1';
+----------------------+
| Total_SKS_Semester_1 |
+----------------------+
|                   22 |
+----------------------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select COUNT(Nama_MK) as Total_MK From Tabel_MK;
+----------+
| Total_MK |
+----------+
|       20 |
+----------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select COUNT(Nama_MK) as Total_MK_Semester_1 From Tabel_MK where Semester='1';
+---------------------+
| Total_MK_Semester_1 |
+---------------------+
|                   8 |
+---------------------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select AVG(SKS) as Average_SKS From Tabel_MK;
+-------------+
| Average_SKS |
+-------------+
|      2.7000 |
+-------------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select AVG(SKS) as Average_SKS_Semester_1 From Tabel_MK where Semester='1';
+------------------------+
| Average_SKS_Semester_1 |
+------------------------+
|                 2.7500 |
+------------------------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select MIN(SKS) as Min_SKS From Tabel_MK;
+---------+
| Min_SKS |
+---------+
|       2 |
+---------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select MAX(SKS) as Min_SKS From Tabel_MK;
+---------+
| Min_SKS |
+---------+
|       4 |
+---------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select MAX(Semester) as Max_Semester,COUNT(Nama_MK) as Total_MK,SUM(SKS) as Total_SKS from Tabel_MK;
+--------------+----------+-----------+
| Max_Semester | Total_MK | Total_SKS |
+--------------+----------+-----------+
|            3 |       20 |        54 |
+--------------+----------+-----------+
1 row in set (0.00 sec)

MariaDB [Akademik]> Select Semester, COUNT(*) as Total_MK, SUM(SKS) as Total_SKS
    -> from Tabel_MK
    -> group by Semester
    -> order by Semester;
+----------+----------+-----------+
| Semester | Total_MK | Total_SKS |
+----------+----------+-----------+
|        1 |        8 |        22 |
|        2 |        6 |        16 |
|        3 |        6 |        16 |
+----------+----------+-----------+
3 rows in set (0.05 sec)

MariaDB [Akademik]> Ctrl-C -- exit!
Aborted
salomo@silaban-X455LAB:~$
http://www.salomo.tk/2017/11/perintah-fungsi-sum-count-max-min-avg.html

1 comment:

  1. Salomo516.Blogspot.Com: Perintah Fungsi Sum, Count, Max, Min, And Avg Pada Mysql Dengan Cmd And Command Line Linux >>>>> Download Now

    >>>>> Download Full

    Salomo516.Blogspot.Com: Perintah Fungsi Sum, Count, Max, Min, And Avg Pada Mysql Dengan Cmd And Command Line Linux >>>>> Download LINK

    >>>>> Download Now

    Salomo516.Blogspot.Com: Perintah Fungsi Sum, Count, Max, Min, And Avg Pada Mysql Dengan Cmd And Command Line Linux >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete