You are on page 1of 7

mysql> create table tblTugas2 (NIS Char(5) Not Null primary key,

-> NamaSiswa Varchar(25),


-> Tgl_Lahir Date Not Null Default '0000-00-00',
-> Teori Decimal(6,2) Not Null default 0,
-> Praktek Decimal(6,2) Not Null default 0);
Query OK, 0 rows affected (0.08 sec)
mysql> desc tbltugas2;
+-----------+--------------+------+-----+------------+-------+
| Field
| Type
| Null | Key | Default
| Extra |
+-----------+--------------+------+-----+------------+-------+
| NIS
| char(5)
| NO | PRI | NULL
|
|
| NamaSiswa | varchar(25) | YES |
| NULL
|
|
| Tgl_Lahir | date
| NO |
| 0000-00-00 |
|
| Teori
| decimal(6,2) | NO |
| 0.00
|
|
| Praktek | decimal(6,2) | NO |
| 0.00
|
|
+-----------+--------------+------+-----+------------+-------+
5 rows in set (0.03 sec)
mysql> insert into tbltugas2 values
-> ('10701','Wawan B','1989-05-17',75.50,80.25);
Query OK, 1 row affected (0.02 sec)
mysql> select * from tbltugas2;
+-------+-----------+------------+-------+---------+
| NIS | NamaSiswa | Tgl_Lahir | Teori | Praktek |
+-------+-----------+------------+-------+---------+
| 10701 | Wawan B | 1989-05-17 | 75.50 | 80.25 |
+-------+-----------+------------+-------+---------+
1 row in set (0.00 sec)
mysql> insert into tbltugas2 values
-> ('10702','Siti Fatimah','1990-11-24',95.75,85.50),
-> ('10703','Burhanudin H','1990-06-25',100.00,95.25),
-> ('10704','Ernawati','1989-10-08',50.50,65.75),
-> ('10705','Fransisca P','1990-04-15',75.25,62.50);
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from tbltugas2;
+-------+--------------+------------+--------+---------+
| NIS | NamaSiswa
| Tgl_Lahir | Teori | Praktek |
+-------+--------------+------------+--------+---------+
| 10701 | Wawan B
| 1989-05-17 | 75.50 | 80.25 |
| 10702 | Siti Fatimah | 1990-11-24 | 95.75 | 85.50 |
| 10703 | Burhanudin H | 1990-06-25 | 100.00 | 95.25 |
| 10704 | Ernawati
| 1989-10-08 | 50.50 | 65.75 |
| 10705 | Fransisca P | 1990-04-15 | 75.25 | 62.50 |
+-------+--------------+------------+--------+---------+
5 rows in set (0.00 sec)
mysql> update tbltugas2 set teori = 40.50,praktek=55.25 where nis like '10704';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from tbltugas2;
+-------+--------------+------------+--------+---------+
| NIS | NamaSiswa
| Tgl_Lahir | Teori | Praktek |
+-------+--------------+------------+--------+---------+
| 10701 | Wawan B
| 1989-05-17 | 75.50 | 80.25 |

| 10702 | Siti Fatimah | 1990-11-24 | 95.75 | 85.50 |


| 10703 | Burhanudin H | 1990-06-25 | 100.00 | 95.25 |
| 10704 | Ernawati
| 1989-10-08 | 40.50 | 55.25 |
| 10705 | Fransisca P | 1990-04-15 | 75.25 | 62.50 |
+-------+--------------+------------+--------+---------+
5 rows in set (0.00 sec)
mysql> alter table tbltugas2 add Sex Enum('L','P') Not Null Default 'P' after Tg
l_Lahir;
Query OK, 5 rows affected (0.25 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> desc tbltugas2;
+-----------+---------------+------+-----+------------+-------+
| Field
| Type
| Null | Key | Default
| Extra |
+-----------+---------------+------+-----+------------+-------+
| NIS
| char(5)
| NO | PRI | NULL
|
|
| NamaSiswa | varchar(25) | YES |
| NULL
|
|
| Tgl_Lahir | date
| NO |
| 0000-00-00 |
|
| Sex
| enum('L','P') | NO |
| P
|
|
| Teori
| decimal(6,2) | NO |
| 0.00
|
|
| Praktek | decimal(6,2) | NO |
| 0.00
|
|
+-----------+---------------+------+-----+------------+-------+
6 rows in set (0.02 sec)
mysql> insert into tbltugas2 (NIS,NamaSiswa,Tgl_Lahir,Teori,Praktek) values
-> ('10706','Budiman S','1990-03-10',45.25,78.50),
-> ('10707','Zaenal A','1989-11-18',75.00,100.00),
-> ('10708,'B Yulianti','1990-01-28',35.75,40.50),
'> ('1070;8,'B Yulianti','1990-01-28',35.75,40.50),
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'B Yul
ianti','1990-01-28',35.75,40.50),
('1070' at line 4
-> insert into tbltugas2 (NIS,NamaSiswa,Tgl_Lahir,Teori,Praktek) values
-> ('10706','Budiman S','1990-03-10',45.25,78.50),
-> ('10707','Zaenal A','1989-11-18',75.00,100.00),
-> ('10708','B Yulianti','1990-01-28',35.75,40.50),
-> ('10709','Endang Y','1990-06-21',67.50,80.25),
-> ('10710','M Widodo','1989-02-25',87.00,60.50);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '8,'B
Yulianti','1990-01-28',35.75,40.50),
insert into tbltugas2 (NIS,NamaSiswa,T' at line 1
mysql> select * from tbltugas2;
+-------+--------------+------------+-----+--------+---------+
| NIS | NamaSiswa
| Tgl_Lahir | Sex | Teori | Praktek |
+-------+--------------+------------+-----+--------+---------+
| 10701 | Wawan B
| 1989-05-17 | P | 75.50 | 80.25 |
| 10702 | Siti Fatimah | 1990-11-24 | P | 95.75 | 85.50 |
| 10703 | Burhanudin H | 1990-06-25 | P | 100.00 | 95.25 |
| 10704 | Ernawati
| 1989-10-08 | P | 40.50 | 55.25 |
| 10705 | Fransisca P | 1990-04-15 | P | 75.25 | 62.50 |
+-------+--------------+------------+-----+--------+---------+
5 rows in set (0.00 sec)
mysql>
->
->
->

insert into tbltugas2 (NIS,NamaSiswa,Tgl_Lahir,Teori,Praktek) values


('10706','Budiman S','1990-03-10',45.25,78.50),
('10707','Zaenal A','1989-11-18',75.00,100.00),
('10708','B Yulianti','1990-01-28',35.75,40.50),

-> ('10709','Endang Y','1990-06-21',67.50,80.25),


-> ('10710','M Widodo','1989-02-25',87.00,60.50);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from tbltugas2;
+-------+--------------+------------+-----+--------+---------+
| NIS | NamaSiswa
| Tgl_Lahir | Sex | Teori | Praktek |
+-------+--------------+------------+-----+--------+---------+
| 10701 | Wawan B
| 1989-05-17 | P | 75.50 | 80.25 |
| 10702 | Siti Fatimah | 1990-11-24 | P | 95.75 | 85.50 |
| 10703 | Burhanudin H | 1990-06-25 | P | 100.00 | 95.25 |
| 10704 | Ernawati
| 1989-10-08 | P | 40.50 | 55.25 |
| 10705 | Fransisca P | 1990-04-15 | P | 75.25 | 62.50 |
| 10706 | Budiman S
| 1990-03-10 | P | 45.25 | 78.50 |
| 10707 | Zaenal A
| 1989-11-18 | P | 75.00 | 100.00 |
| 10708 | B Yulianti | 1990-01-28 | P | 35.75 | 40.50 |
| 10709 | Endang Y
| 1990-06-21 | P | 67.50 | 80.25 |
| 10710 | M Widodo
| 1989-02-25 | P | 87.00 | 60.50 |
+-------+--------------+------------+-----+--------+---------+
10 rows in set (0.00 sec)
mysql> update tbltugas2 set sex = 'L' where nis in('10701','10703','10706','1070
7,'10710');
'> ;
'> ';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '10710
');
;
'' at line 1
mysql> update tbltugas2 set sex = 'L' where nis in('10701','10703','10706','1070
7','10710');
Query OK, 5 rows affected (0.05 sec)
Rows matched: 5 Changed: 5 Warnings: 0
mysql> select * from tbltugas2;
+-------+--------------+------------+-----+--------+---------+
| NIS | NamaSiswa
| Tgl_Lahir | Sex | Teori | Praktek |
+-------+--------------+------------+-----+--------+---------+
| 10701 | Wawan B
| 1989-05-17 | L | 75.50 | 80.25 |
| 10702 | Siti Fatimah | 1990-11-24 | P | 95.75 | 85.50 |
| 10703 | Burhanudin H | 1990-06-25 | L | 100.00 | 95.25 |
| 10704 | Ernawati
| 1989-10-08 | P | 40.50 | 55.25 |
| 10705 | Fransisca P | 1990-04-15 | P | 75.25 | 62.50 |
| 10706 | Budiman S
| 1990-03-10 | L | 45.25 | 78.50 |
| 10707 | Zaenal A
| 1989-11-18 | L | 75.00 | 100.00 |
| 10708 | B Yulianti | 1990-01-28 | P | 35.75 | 40.50 |
| 10709 | Endang Y
| 1990-06-21 | P | 67.50 | 80.25 |
| 10710 | M Widodo
| 1989-02-25 | L | 87.00 | 60.50 |
+-------+--------------+------------+-----+--------+---------+
10 rows in set (0.00 sec)
mysql> alter table tbltugas2 add RataNilai Decima(6,2) Unsogned not Null Default
0;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'Decim
a(6,2) Unsogned not Null Default 0' at line 1
mysql> alter table tbltugas2 add RataNilai Decima(6,2) Unsigned not Null Default
0;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'Decim
a(6,2) Unsigned not Null Default 0' at line 1
mysql> alter table tbltugas2 add RataNilai Decimal(6,2) Unsigned not Null Defaul
t 0;
Query OK, 10 rows affected (0.20 sec)
Records: 10 Duplicates: 0 Warnings: 0
mysql> desc tbltugas2
-> ;
+-----------+-----------------------+------+-----+------------+-------+
| Field
| Type
| Null | Key | Default
| Extra |
+-----------+-----------------------+------+-----+------------+-------+
| NIS
| char(5)
| NO | PRI | NULL
|
|
| NamaSiswa | varchar(25)
| YES |
| NULL
|
|
| Tgl_Lahir | date
| NO |
| 0000-00-00 |
|
| Sex
| enum('L','P')
| NO |
| P
|
|
| Teori
| decimal(6,2)
| NO |
| 0.00
|
|
| Praktek | decimal(6,2)
| NO |
| 0.00
|
|
| RataNilai | decimal(6,2) unsigned | NO |
| 0.00
|
|
+-----------+-----------------------+------+-----+------------+-------+
7 rows in set (0.01 sec)
mysql> update tbltugas2 set ratanilai=(0.45*Teori+0.55*Praktek);
Query OK, 10 rows affected, 9 warnings (0.08 sec)
Rows matched: 10 Changed: 10 Warnings: 9
mysql> select * from tbltugas2;
+-------+--------------+------------+-----+--------+---------+-----------+
| NIS | NamaSiswa
| Tgl_Lahir | Sex | Teori | Praktek | RataNilai |
+-------+--------------+------------+-----+--------+---------+-----------+
| 10701 | Wawan B
| 1989-05-17 | L | 75.50 | 80.25 |
78.11 |
| 10702 | Siti Fatimah | 1990-11-24 | P | 95.75 | 85.50 |
90.11 |
| 10703 | Burhanudin H | 1990-06-25 | L | 100.00 | 95.25 |
97.39 |
| 10704 | Ernawati
| 1989-10-08 | P | 40.50 | 55.25 |
48.61 |
| 10705 | Fransisca P | 1990-04-15 | P | 75.25 | 62.50 |
68.24 |
| 10706 | Budiman S
| 1990-03-10 | L | 45.25 | 78.50 |
63.54 |
| 10707 | Zaenal A
| 1989-11-18 | L | 75.00 | 100.00 |
88.75 |
| 10708 | B Yulianti | 1990-01-28 | P | 35.75 | 40.50 |
38.36 |
| 10709 | Endang Y
| 1990-06-21 | P | 67.50 | 80.25 |
74.51 |
| 10710 | M Widodo
| 1989-02-25 | L | 87.00 | 60.50 |
72.43 |
+-------+--------------+------------+-----+--------+---------+-----------+
10 rows in set (0.00 sec)
mysql> alter table tbltugas2 add keterangan enum('Lulus','Gagal') Not NUll Defau
lt 'Lulus';
Query OK, 10 rows affected (0.11 sec)
Records: 10 Duplicates: 0 Warnings: 0
mysql> desc tbltugas2
-> ;
+------------+-----------------------+------+-----+------------+-------+
| Field
| Type
| Null | Key | Default
| Extra |
+------------+-----------------------+------+-----+------------+-------+
| NIS
| char(5)
| NO | PRI | NULL
|
|
| NamaSiswa | varchar(25)
| YES |
| NULL
|
|
| Tgl_Lahir | date
| NO |
| 0000-00-00 |
|
| Sex
| enum('L','P')
| NO |
| P
|
|
| Teori
| decimal(6,2)
| NO |
| 0.00
|
|
| Praktek
| decimal(6,2)
| NO |
| 0.00
|
|

| RataNilai | decimal(6,2) unsigned | NO |


| 0.00
|
|
| keterangan | enum('Lulus','Gagal') | NO |
| Lulus
|
|
+------------+-----------------------+------+-----+------------+-------+
8 rows in set (0.03 sec)
mysql> update tbltugas2 set Keterangan='Gagal' where Ratanilai <= 75;
Query OK, 6 rows affected (0.03 sec)
Rows matched: 6 Changed: 6 Warnings: 0
mysql> select * from tbltugas2;
+-------+--------------+------------+-----+--------+---------+-----------+-----------+
| NIS | NamaSiswa
| Tgl_Lahir | Sex | Teori | Praktek | RataNilai | keter
angan |
+-------+--------------+------------+-----+--------+---------+-----------+-----------+
| 10701 | Wawan B
| 1989-05-17 | L | 75.50 | 80.25 |
78.11 | Lulus
|
| 10702 | Siti Fatimah | 1990-11-24 | P | 95.75 | 85.50 |
90.11 | Lulus
|
| 10703 | Burhanudin H | 1990-06-25 | L | 100.00 | 95.25 |
97.39 | Lulus
|
| 10704 | Ernawati
| 1989-10-08 | P | 40.50 | 55.25 |
48.61 | Gagal
|
| 10705 | Fransisca P | 1990-04-15 | P | 75.25 | 62.50 |
68.24 | Gagal
|
| 10706 | Budiman S
| 1990-03-10 | L | 45.25 | 78.50 |
63.54 | Gagal
|
| 10707 | Zaenal A
| 1989-11-18 | L | 75.00 | 100.00 |
88.75 | Lulus
|
| 10708 | B Yulianti | 1990-01-28 | P | 35.75 | 40.50 |
38.36 | Gagal
|
| 10709 | Endang Y
| 1990-06-21 | P | 67.50 | 80.25 |
74.51 | Gagal
|
| 10710 | M Widodo
| 1989-02-25 | L | 87.00 | 60.50 |
72.43 | Gagal
|
+-------+--------------+------------+-----+--------+---------+-----------+-----------+
10 rows in set (0.00 sec)
mysql> select * from tbltugas2
-> where sex like 'P' or keterangan like 'Lulus'
-> order by ratanilai desc;
+-------+--------------+------------+-----+--------+---------+-----------+-----------+
| NIS | NamaSiswa
| Tgl_Lahir | Sex | Teori | Praktek | RataNilai | keter
angan |
+-------+--------------+------------+-----+--------+---------+-----------+-----------+
| 10703 | Burhanudin H | 1990-06-25 | L | 100.00 | 95.25 |
97.39 | Lulus
|
| 10702 | Siti Fatimah | 1990-11-24 | P | 95.75 | 85.50 |
90.11 | Lulus
|
| 10707 | Zaenal A
| 1989-11-18 | L | 75.00 | 100.00 |
88.75 | Lulus
|
| 10701 | Wawan B
| 1989-05-17 | L | 75.50 | 80.25 |
78.11 | Lulus
|
| 10709 | Endang Y
| 1990-06-21 | P | 67.50 | 80.25 |
74.51 | Gagal
|
| 10705 | Fransisca P | 1990-04-15 | P | 75.25 | 62.50 |
68.24 | Gagal

|
| 10704 | Ernawati
| 1989-10-08 | P | 40.50 | 55.25 |
48.61 | Gagal
|
| 10708 | B Yulianti | 1990-01-28 | P | 35.75 | 40.50 |
38.36 | Gagal
|
+-------+--------------+------------+-----+--------+---------+-----------+-----------+
8 rows in set (1.94 sec)
mysql> select NIS,NamaSiswa,teori,praktekratanilai,keterangan from tbltugas2
-> where ratanilai between 50 and 75
-> order by ratanilai desc;
ERROR 1054 (42S22): Unknown column 'praktekratanilai' in 'field list'
mysql> select NIS,NamaSiswa,teori,praktek,ratanilai,keterangan from tbltugas2
-> where ratanilai between 50 and 75
-> order by ratanilai desc;
+-------+-------------+-------+---------+-----------+------------+
| NIS | NamaSiswa | teori | praktek | ratanilai | keterangan |
+-------+-------------+-------+---------+-----------+------------+
| 10709 | Endang Y
| 67.50 | 80.25 |
74.51 | Gagal
|
| 10710 | M Widodo
| 87.00 | 60.50 |
72.43 | Gagal
|
| 10705 | Fransisca P | 75.25 | 62.50 |
68.24 | Gagal
|
| 10706 | Budiman S | 45.25 | 78.50 |
63.54 | Gagal
|
+-------+-------------+-------+---------+-----------+------------+
4 rows in set (0.01 sec)
mysql> select NIs,Namasiswa,Tgl_Lahir,dayname(tgl_lahir) NamaHari,keterangan
-> from tbltugas2
-> where dayname(tgl_lahir) in('Sunday','Tuesday') or keterangan like 'Gagal
'
-> order by dayofweek(tgl_lahir);
+-------+-------------+------------+----------+------------+
| NIs | Namasiswa | Tgl_Lahir | NamaHari | keterangan |
+-------+-------------+------------+----------+------------+
| 10704 | Ernawati
| 1989-10-08 | Sunday | Gagal
|
| 10705 | Fransisca P | 1990-04-15 | Sunday | Gagal
|
| 10708 | B Yulianti | 1990-01-28 | Sunday | Gagal
|
| 10709 | Endang Y
| 1990-06-21 | Thursday | Gagal
|
| 10706 | Budiman S | 1990-03-10 | Saturday | Gagal
|
| 10710 | M Widodo
| 1989-02-25 | Saturday | Gagal
|
+-------+-------------+------------+----------+------------+
6 rows in set (0.11 sec)
mysql> select NIs,Namasiswa,Tgl_Lahir,dayname(tgl_lahir) NamaHari,keterangan
-> from tbltugas2;
+-------+--------------+------------+-----------+------------+
| NIs | Namasiswa
| Tgl_Lahir | NamaHari | keterangan |
+-------+--------------+------------+-----------+------------+
| 10701 | Wawan B
| 1989-05-17 | Wednesday | Lulus
|
| 10702 | Siti Fatimah | 1990-11-24 | Saturday | Lulus
|
| 10703 | Burhanudin H | 1990-06-25 | Monday
| Lulus
|
| 10704 | Ernawati
| 1989-10-08 | Sunday
| Gagal
|
| 10705 | Fransisca P | 1990-04-15 | Sunday
| Gagal
|
| 10706 | Budiman S
| 1990-03-10 | Saturday | Gagal
|
| 10707 | Zaenal A
| 1989-11-18 | Saturday | Lulus
|
| 10708 | B Yulianti | 1990-01-28 | Sunday
| Gagal
|
| 10709 | Endang Y
| 1990-06-21 | Thursday | Gagal
|
| 10710 | M Widodo
| 1989-02-25 | Saturday | Gagal
|
+-------+--------------+------------+-----------+------------+
10 rows in set (0.00 sec)

mysql> \t

You might also like