Sie sind auf Seite 1von 10

mysql> create database loans;

Query OK, 1 row affected (0.00 sec)


mysql> use loans;
Database changed
mysql> create table loan_accounts( AccNo integer(30) not null, Cust_Name varchar
(30) not null, Loan_Amount integer(10) not null,
Installments integer(5) not null, Int_Rate decimal(5,2), Start_Date date not nu
ll, Interest integer(30));
Query OK, 0 rows affected (0.12 sec)
mysql> insert into loan_accounts values(1,"R.K. Gupta",300000,36,12.00,'2009-0719',null);
Query OK, 1 row affected (0.03 sec)
mysql> insert into loan_accounts values(2,"S.P. Sharma",500000,48,10.00,'2008-03
-22',null);
Query OK, 1 row affected (0.02 sec)
mysql> insert into loan_accounts values(3,"K.P. Jain",300000,36,null,'2007-03-08
',null);
Query OK, 1 row affected (0.02 sec)
mysql> insert into loan_accounts values(4,"M.P. Yadav",800000,60,10.00,'2008-012
-06',null);
Query OK, 1 row affected (0.05 sec)
mysql> insert into loan_accounts values(5,"S.P. Sinha",200000,36,12.50,'2010-0103',null);
Query OK, 1 row affected (0.01 sec)
mysql> insert into loan_accounts values(6,"P. Sharma",700000,60,12.50,'2008-06-0
5',null);
Query OK, 1 row affected (0.02 sec)
mysql> insert into loan_accounts values(7,"K.S. Dhall",500000,48,null,'2008-03-0
5',null);
Query OK, 1 row affected (0.01 sec)
mysql> select* from loan_accounts;
+-------+-------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Int
erest |
+-------+-------------+-------------+--------------+----------+------------+---------+
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
|
2 | S.P. Sharma |
500000 |
48 |
10.00 | 2008-03-22 |
NULL |
|
3 | K.P. Jain |
300000 |
36 |
NULL | 2007-03-08 |
NULL |
|
4 | M.P. Yadav |
800000 |
60 |
10.00 | 2008-12-06 |
NULL |
|
5 | S.P. Sinha |
200000 |
36 |
12.50 | 2010-01-03 |
NULL |
|
6 | P. Sharma |
700000 |
60 |
12.50 | 2008-06-05 |
NULL |
|
7 | K.S. Dhall |
500000 |
48 |
NULL | 2008-03-05 |
NULL |

+-------+-------------+-------------+--------------+----------+------------+---------+
7 rows in set (0.00 sec)
mysql> select AccNo,Cust_Name,Loan_Amount from loan_accounts;
+-------+-------------+-------------+
| AccNo | Cust_Name | Loan_Amount |
+-------+-------------+-------------+
|
1 | R.K. Gupta |
300000 |
|
2 | S.P. Sharma |
500000 |
|
3 | K.P. Jain |
300000 |
|
4 | M.P. Yadav |
800000 |
|
5 | S.P. Sinha |
200000 |
|
6 | P. Sharma |
700000 |
|
7 | K.S. Dhall |
500000 |
+-------+-------------+-------------+
7 rows in set (0.00 sec)
mysql> select* from loan_accounts where Installments<40;
+-------+------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Inte
rest |
+-------+------------+-------------+--------------+----------+------------+---------+
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
|
3 | K.P. Jain |
300000 |
36 |
NULL | 2007-03-08 |
NULL |
|
5 | S.P. Sinha |
200000 |
36 |
12.50 | 2010-01-03 |
NULL |
+-------+------------+-------------+--------------+----------+------------+---------+
3 rows in set (0.00 sec)
mysql> select AccNo,Loan_Amount from loan_accounts where Start_Date<'2009-04-01'
;
+-------+-------------+
| AccNo | Loan_Amount |
+-------+-------------+
|
2 |
500000 |
|
3 |
300000 |
|
4 |
800000 |
|
6 |
700000 |
|
7 |
500000 |
+-------+-------------+
5 rows in set (0.00 sec)
mysql> select Int_Rate from loan_accounts where Start_Date>'2009-04-01';
+----------+
| Int_Rate |
+----------+
|
12.00 |
|
12.50 |
+----------+
2 rows in set (0.00 sec)
mysql> select * from loan_accounts where Int_Rate is null;
+-------+------------+-------------+--------------+----------+------------+---------+

| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Inte


rest |
+-------+------------+-------------+--------------+----------+------------+---------+
|
3 | K.P. Jain |
300000 |
36 |
NULL | 2007-03-08 |
NULL |
|
7 | K.S. Dhall |
500000 |
48 |
NULL | 2008-03-05 |
NULL |
+-------+------------+-------------+--------------+----------+------------+---------+
2 rows in set (0.00 sec)
mysql> select * from loan_accounts where Int_Rate is not null;
+-------+-------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Int
erest |
+-------+-------------+-------------+--------------+----------+------------+---------+
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
|
2 | S.P. Sharma |
500000 |
48 |
10.00 | 2008-03-22 |
NULL |
|
4 | M.P. Yadav |
800000 |
60 |
10.00 | 2008-12-06 |
NULL |
|
5 | S.P. Sinha |
200000 |
36 |
12.50 | 2010-01-03 |
NULL |
|
6 | P. Sharma |
700000 |
60 |
12.50 | 2008-06-05 |
NULL |
+-------+-------------+-------------+--------------+----------+------------+---------+
5 rows in set (0.00 sec)
mysql> select distinct Loan_Amount from loan_accounts;
+-------------+
| Loan_Amount |
+-------------+
|
300000 |
|
500000 |
|
800000 |
|
200000 |
|
700000 |
+-------------+
5 rows in set (0.03 sec)
mysql> select distinct Installments from loan_accounts;
+--------------+
| Installments |
+--------------+
|
36 |
|
48 |
|
60 |
+--------------+
3 rows in set (0.00 sec)
mysql> select* from loan_accounts where Installments>36 && Start_Date>'2008-12-3
1';
Empty set (0.02 sec)
mysql> select Cust_Name,Loan_Amount from loan_accounts where Installments!=36;

+-------------+-------------+
| Cust_Name | Loan_Amount |
+-------------+-------------+
| S.P. Sharma |
500000 |
| M.P. Yadav |
800000 |
| P. Sharma |
700000 |
| K.S. Dhall |
500000 |
+-------------+-------------+
4 rows in set (0.00 sec)
mysql> select Cust_Name,Loan_Amount from loan_accounts where Int_Rate>12 || Loan
_Amount<500000;
+------------+-------------+
| Cust_Name | Loan_Amount |
+------------+-------------+
| R.K. Gupta |
300000 |
| K.P. Jain |
300000 |
| S.P. Sinha |
200000 |
| P. Sharma |
700000 |
+------------+-------------+
4 rows in set (0.00 sec)
mysql> select * from loan_accounts where year(Start_Date)=2009;
+-------+------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Inte
rest |
+-------+------------+-------------+--------------+----------+------------+---------+
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
+-------+------------+-------------+--------------+----------+------------+---------+
1 row in set (0.02 sec)
mysql> select * from loan_accounts where Loan_Amount>400000 && Loan_Amount<50000
0;
Empty set (0.00 sec)
mysql> select* from loan_accounts where int_rate>11 && int_rate<12;
Empty set (0.00 sec)
mysql> select cust_name,loan_amount from loan_accounts where installments in (24
,36,48);
+-------------+-------------+
| cust_name | loan_amount |
+-------------+-------------+
| R.K. Gupta |
300000 |
| S.P. Sharma |
500000 |
| K.P. Jain |
300000 |
| S.P. Sinha |
200000 |
| K.S. Dhall |
500000 |
+-------------+-------------+
5 rows in set (0.08 sec)
mysql> select* from loan_accounts where loan_amount between 400000 and 500000;
+-------+-------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Int
erest |

+-------+-------------+-------------+--------------+----------+------------+---------+
|
2 | S.P. Sharma |
500000 |
48 |
10.00 | 2008-03-22 |
NULL |
|
7 | K.S. Dhall |
500000 |
48 |
NULL | 2008-03-05 |
NULL |
+-------+-------------+-------------+--------------+----------+------------+---------+
2 rows in set (0.03 sec)
mysql> select* from loan_accounts where int_rate between 11 and 12;
+-------+------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Inte
rest |
+-------+------------+-------------+--------------+----------+------------+---------+
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
+-------+------------+-------------+--------------+----------+------------+---------+
1 row in set (0.00 sec)
mysql> select accno,cust_name,loan_amount from loan_accounts where cust_name lik
e "%Sharma";
+-------+-------------+-------------+
| accno | cust_name | loan_amount |
+-------+-------------+-------------+
|
2 | S.P. Sharma |
500000 |
|
6 | P. Sharma |
700000 |
+-------+-------------+-------------+
2 rows in set (0.00 sec)
mysql> select accno,cust_name,loan_amount from loan_accounts where cust_name lik
e "%a";
+-------+-------------+-------------+
| accno | cust_name | loan_amount |
+-------+-------------+-------------+
|
1 | R.K. Gupta |
300000 |
|
2 | S.P. Sharma |
500000 |
|
5 | S.P. Sinha |
200000 |
|
6 | P. Sharma |
700000 |
+-------+-------------+-------------+
4 rows in set (0.00 sec)
mysql> select accno,cust_name,loan_amount from loan_accounts where cust_name lik
e "%a%";
+-------+-------------+-------------+
| accno | cust_name | loan_amount |
+-------+-------------+-------------+
|
1 | R.K. Gupta |
300000 |
|
2 | S.P. Sharma |
500000 |
|
3 | K.P. Jain |
300000 |
|
4 | M.P. Yadav |
800000 |
|
5 | S.P. Sinha |
200000 |
|
6 | P. Sharma |
700000 |
|
7 | K.S. Dhall |
500000 |
+-------+-------------+-------------+
7 rows in set (0.00 sec)

mysql> select accno,cust_name,loan_amount from loan_accounts where cust_name not


like "%P%";
+-------+------------+-------------+
| accno | cust_name | loan_amount |
+-------+------------+-------------+
|
7 | K.S. Dhall |
500000 |
+-------+------------+-------------+
1 row in set (0.00 sec)
mysql> select accno,cust_name,loan_amount from loan_accounts where cust_name not
like "a_";
+-------+-------------+-------------+
| accno | cust_name | loan_amount |
+-------+-------------+-------------+
|
1 | R.K. Gupta |
300000 |
|
2 | S.P. Sharma |
500000 |
|
3 | K.P. Jain |
300000 |
|
4 | M.P. Yadav |
800000 |
|
5 | S.P. Sinha |
200000 |
|
6 | P. Sharma |
700000 |
|
7 | K.S. Dhall |
500000 |
+-------+-------------+-------------+
7 rows in set (0.00 sec)
mysql> select accno,cust_name,loan_amount from loan_accounts where cust_name lik
e "%a_";
+-------+------------+-------------+
| accno | cust_name | loan_amount |
+-------+------------+-------------+
|
4 | M.P. Yadav |
800000 |
+-------+------------+-------------+
1 row in set (0.00 sec)
mysql> select* from loan_accounts order by loan_amount;
+-------+-------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Int
erest |
+-------+-------------+-------------+--------------+----------+------------+---------+
|
5 | S.P. Sinha |
200000 |
36 |
12.50 | 2010-01-03 |
NULL |
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
|
3 | K.P. Jain |
300000 |
36 |
NULL | 2007-03-08 |
NULL |
|
2 | S.P. Sharma |
500000 |
48 |
10.00 | 2008-03-22 |
NULL |
|
7 | K.S. Dhall |
500000 |
48 |
NULL | 2008-03-05 |
NULL |
|
6 | P. Sharma |
700000 |
60 |
12.50 | 2008-06-05 |
NULL |
|
4 | M.P. Yadav |
800000 |
60 |
10.00 | 2008-12-06 |
NULL |
+-------+-------------+-------------+--------------+----------+------------+---------+
7 rows in set (0.02 sec)
mysql> select* from loan_accounts order by start_date desc;
+-------+-------------+-------------+--------------+----------+------------+----

------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Int
erest |
+-------+-------------+-------------+--------------+----------+------------+---------+
|
5 | S.P. Sinha |
200000 |
36 |
12.50 | 2010-01-03 |
NULL |
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
|
4 | M.P. Yadav |
800000 |
60 |
10.00 | 2008-12-06 |
NULL |
|
6 | P. Sharma |
700000 |
60 |
12.50 | 2008-06-05 |
NULL |
|
2 | S.P. Sharma |
500000 |
48 |
10.00 | 2008-03-22 |
NULL |
|
7 | K.S. Dhall |
500000 |
48 |
NULL | 2008-03-05 |
NULL |
|
3 | K.P. Jain |
300000 |
36 |
NULL | 2007-03-08 |
NULL |
+-------+-------------+-------------+--------------+----------+------------+---------+
7 rows in set (0.00 sec)
mysql> select* from loan_accounts order by loan_amount asc,start_date desc;
+-------+-------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | Int
erest |
+-------+-------------+-------------+--------------+----------+------------+---------+
|
5 | S.P. Sinha |
200000 |
36 |
12.50 | 2010-01-03 |
NULL |
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 |
NULL |
|
3 | K.P. Jain |
300000 |
36 |
NULL | 2007-03-08 |
NULL |
|
2 | S.P. Sharma |
500000 |
48 |
10.00 | 2008-03-22 |
NULL |
|
7 | K.S. Dhall |
500000 |
48 |
NULL | 2008-03-05 |
NULL |
|
6 | P. Sharma |
700000 |
60 |
12.50 | 2008-06-05 |
NULL |
|
4 | M.P. Yadav |
800000 |
60 |
10.00 | 2008-12-06 |
NULL |
+-------+-------------+-------------+--------------+----------+------------+---------+
7 rows in set (0.00 sec)
mysql> update loan_accounts set int_rate=11.50 where int_rate is null;
Query OK, 2 rows affected (0.05 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> update loan_accounts set int_rate=int_rate+.50 where loan_amount>400000;
Query OK, 4 rows affected (0.05 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> update loan_accounts set interest=((loan_amount*int_rate*installments)/12
)/100;
Query OK, 7 rows affected (0.05 sec)
Rows matched: 7 Changed: 7 Warnings: 0

mysql> select* from loan_accounts;


+-------+-------------+-------------+--------------+----------+------------+---------+
| AccNo | Cust_Name | Loan_Amount | Installments | Int_Rate | Start_Date | int
erest |
+-------+-------------+-------------+--------------+----------+------------+---------+
|
1 | R.K. Gupta |
300000 |
36 |
12.00 | 2009-07-19 | 1
08000 |
|
2 | S.P. Sharma |
500000 |
48 |
10.50 | 2008-03-22 | 2
10000 |
|
3 | K.P. Jain |
300000 |
36 |
11.50 | 2007-03-08 | 1
03500 |
|
4 | M.P. Yadav |
800000 |
60 |
10.50 | 2008-12-06 | 4
20000 |
|
5 | S.P. Sinha |
200000 |
36 |
12.50 | 2010-01-03 |
75000 |
|
6 | P. Sharma |
700000 |
60 |
13.00 | 2008-06-05 | 4
55000 |
|
7 | K.S. Dhall |
500000 |
48 |
12.00 | 2008-03-05 | 2
40000 |
+-------+-------------+-------------+--------------+----------+------------+---------+
7 rows in set (0.00 sec)
mysql> delete from loan_accounts where year(start_date)<2007;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from loan_accounts where cust_name like "K.P. Jain";
Query OK, 1 row affected (0.03 sec)
mysql> alter table loan_accounts add Category char(1);
Query OK, 6 rows affected (0.16 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> select cust_name, length(cust_name),lcase(cust_name),ucase(cust_name) fro
m loan_accounts where int_rate<11.00;
+-------------+-------------------+------------------+------------------+
| cust_name | length(cust_name) | lcase(cust_name) | ucase(cust_name) |
+-------------+-------------------+------------------+------------------+
| S.P. Sharma |
11 | s.p. sharma
| S.P. SHARMA
|
| M.P. Yadav |
10 | m.p. yadav
| M.P. YADAV
|
+-------------+-------------------+------------------+------------------+
2 rows in set (0.08 sec)
mysql> select left(cust_name,3),right(cust_name,3),substr(cust_name,1,3) from lo
an_accounts where int_rate>10.00;
+-------------------+--------------------+-----------------------+
| left(cust_name,3) | right(cust_name,3) | substr(cust_name,1,3) |
+-------------------+--------------------+-----------------------+
| R.K
| pta
| R.K
|
| S.P
| rma
| S.P
|
| M.P
| dav
| M.P
|
| S.P
| nha
| S.P
|
| P.
| rma
| P.
|
| K.S
| all
| K.S
|
+-------------------+--------------------+-----------------------+
6 rows in set (0.00 sec)

mysql> select right(cust_name,3),substr(cust_name,5) from loan_accounts;


+--------------------+---------------------+
| right(cust_name,3) | substr(cust_name,5) |
+--------------------+---------------------+
| pta
| Gupta
|
| rma
| Sharma
|
| dav
| Yadav
|
| nha
| Sinha
|
| rma
| harma
|
| all
| Dhall
|
+--------------------+---------------------+
6 rows in set (0.00 sec)
mysql> select dayname(start_date) from loan_accounts;
+---------------------+
| dayname(start_date) |
+---------------------+
| Sunday
|
| Saturday
|
| Saturday
|
| Sunday
|
| Thursday
|
| Wednesday
|
+---------------------+
6 rows in set (0.00 sec)
mysql> select round(int_rate*110/100,2) from loan_accounts where int_rate>10;
+---------------------------+
| round(int_rate*110/100,2) |
+---------------------------+
|
13.20 |
|
11.55 |
|
11.55 |
|
13.75 |
|
14.30 |
|
13.20 |
+---------------------------+
6 rows in set (0.00 sec)
mysql> select pow(4,3),pow(3,4);
+----------+----------+
| pow(4,3) | pow(3,4) |
+----------+----------+
|
64 |
81 |
+----------+----------+
1 row in set (0.01 sec)
mysql> select round(543.5694,2),round(543.5694),round(543.5694,-1);
+-------------------+-----------------+--------------------+
| round(543.5694,2) | round(543.5694) | round(543.5694,-1) |
+-------------------+-----------------+--------------------+
|
543.57 |
544 |
540 |
+-------------------+-----------------+--------------------+
1 row in set (0.00 sec)
mysql> select truncate(543.5694,2),truncate(543.5694,-1);
+----------------------+-----------------------+
| truncate(543.5694,2) | truncate(543.5694,-1) |
+----------------------+-----------------------+
|
543.56 |
540 |

+----------------------+-----------------------+
1 row in set (0.00 sec)
mysql> select length("Prof. M.L. Sharma");
+-----------------------------+
| length("Prof. M.L. Sharma") |
+-----------------------------+
|
17 |
+-----------------------------+
1 row in set (0.00 sec)
mysql> select concat("Sheikh","Haroon")"FULL NAME";
+--------------+
| FULL NAME
|
+--------------+
| SheikhHaroon |
+--------------+
1 row in set (0.00 sec)
mysql> select year(curdate()),month(curdate()),day(curdate());
+-----------------+------------------+----------------+
| year(curdate()) | month(curdate()) | day(curdate()) |
+-----------------+------------------+----------------+
|
2015 |
3 |
23 |
+-----------------+------------------+----------------+
1 row in set (0.00 sec)
mysql> select dayofyear(curdate()),dayofmonth(curdate()),dayname(curdate());
+----------------------+-----------------------+--------------------+
| dayofyear(curdate()) | dayofmonth(curdate()) | dayname(curdate()) |
+----------------------+-----------------------+--------------------+
|
82 |
23 | Monday
|
+----------------------+-----------------------+--------------------+
1 row in set (0.00 sec)
mysql> select left("Unicode",3),right("Unicode",4);
+-------------------+--------------------+
| left("Unicode",3) | right("Unicode",4) |
+-------------------+--------------------+
| Uni
| code
|
+-------------------+--------------------+
1 row in set (0.00 sec)
mysql> select instr("Unicode","co"),instr("Unicode","cd");
+-----------------------+-----------------------+
| instr("Unicode","co") | instr("Unicode","cd") |
+-----------------------+-----------------------+
|
4 |
0 |
+-----------------------+-----------------------+
1 row in set (0.00 sec)
mysql> select mid("Informatics",3,4),substr("Practices",3);
+------------------------+-----------------------+
| mid("Informatics",3,4) | substr("Practices",3) |
+------------------------+-----------------------+
| form
| actices
|
+------------------------+-----------------------+
1 row in set (0.00 sec)

Das könnte Ihnen auch gefallen