0% found this document useful (0 votes)
94 views

MySQL Practicals

Uploaded by

venkat krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
94 views

MySQL Practicals

Uploaded by

venkat krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
1. Consider a database LOANS with the following table: Table: LOANS. 1 [Rak Gupta] 300000 36 12.00 | 19-07-2009 | 90 2 |sp.sharma | 500000, a 10.00 {22-03-2008 | —te5p 3 _[KP.tain 300000 36 Nutt | 08-03-2007 | reap ‘4 [Mp yadav | 200000 60 10.00 | 06-12-2008 | — nas 5_[SP.sinha "200000 36 1250 | 05-01-2010 | —asop © [P.Sharma 700000 60 12.50 | 05-06-2008 | — 3509 7 [KS-Dhall 500000 nm Nutt [05-03-2008 | a9 ‘Answer the following questions. 1. Create the database LOANS, Ans. Mysql> Create Database LOANS; 2. Use the database LOANS. ‘Ans. Mysql> Use LOANS; 3. Create the table Loans and insert tuples in it. Ans Mysql>Create Table Loans (AccNo int primary key, Cust_Name varchar(30), Loan_Amount int, Instalment int Int_Rate number(5,3), Start_Date date, Interest number(7,2)) -Mysql> Insert into Loans values (1/RK. GUPTW,300000,36,12.0;2009-07-19'; 4. Display the details ofall the loans. Ans. Mysql> Select * from Loans; 5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans. Ans. Mysql> Select AccNo,Cust_Name,Loan_Amount from Loan_Acc; 6. Display the details ofall te loans with less than 40 instalments. Ans. ‘Mysql> Select * from Loans where instalment <40; ‘Scanned with CamScanner = ery the AceNO and fe AccNo and Loan_ Am sly th Amount ofall the loans started before 01 POINT wsdl SEC AEENO, Loan_Armount om Looe ne hee wivete Start Date <2009-04.01; a. iply the tRat of al the loans started ater 01-04-2002 ‘Mysql Select Int Rate from Loans wi sos __ Muy Slet Fate fom eas where Sia. dte>'2009-005 ® splay the detalls ofall the loans whose rate of intrest is NULL 2 Mysa> Selec * fom Loans where ita fe NULL MF isply the deals of al the loans whose ate of interest NOT NULL os Masa Seect* Flom LOANS whore Int stels nt NUL: 11, cisly theamountsof various loans fom the able OANS.Aloanamountshouldappearonlyonce. ss. Mysab Select DISTINCT Loan_Amount fom LOANS; 12 Diplay the numberof instalments of various loans from the table LOANS. Am instalment should sppen only once. os. Mysql Select DISTINCT Instalment fom LOANS 13. Disply the detals ofall the loans started after 31-12-2008 for which the numberof instalments are moe than 36 os Mysal> Select * rom LOANS where Star_Date>'2008-12-31 and instalment>36; 14. Disply the detalls of all th loans inthe ascending order of thelr Loan_Amount ‘ins, _-Mysql> Select * from LOANS ORDER BY Loan_Amount; 15, Delete the records of ll the loans whose start date is before 2007. ‘es, Mysql> Delete From LOANS Where Year(Start_Date)<2007; 16. Delete the records ofall the loans of 'KP. Jan Jos, Mysql Delete From LOANS Where Cust_Name="P Jin’ 17. Add another column Category of type CHAR() in the Loan table. ‘ns, Mysql> Alter Table LOANS ADD\Category CHAR() Using Aggregate Functions 18. Display the sum of all Loan Amount whose Interest rateis greater than 10. fos, Mysal> Select sum(Loan_Amount) rom LOANS Where Interest >10; 18, splay the Maximum Interest from Loans table. Jos. Mysal> Select Matinterst fom LOANS: 2. Display the count of aloan holders whose name ends with Shara 405. Mya Select Count() from LOANS Where Cust Name Like Sharm 21 Display the count of all loan holders whose Interest is Null 4. Mysqt> Select Count frm LOANS Where Interests NUL: 2 bisplay the nterest-vise deal of Loan Account Holders os, ysl Selet* fom LOANS Group By Interest 23. spay the Interest-wise details of Loan Account Holders with atleast 10 stalments remaining As, yal select from LOANS Group By Interest Having Instalment>=10; 2 Dipayaheptevest ise count af al oan holders whose Intalment due s more than Sin each group. ‘ns, Mysals Select Count) from LOANS Group By Interest faving Instalment>s; ‘Scanned with CamScanner, 25. Consider the EMP table and give the SQL statements for the following questions: EMP Si SS SE Da a ene 369_| SMITH. CLERK 16-12-1990 | 105000 | 20000 | 10 499_[ ANYA SALESMAN 20-02-1991 | 160000 | 20000 | 20 8566 _| MAHADEVAN | MANAGER (02-04-1991 | _ 2985.00 nuu_| 30 8654 | MOMIN ‘SALESMAN. 28-09-1991 | 125000 | 40000 | 20 '3698_[ BINA, MANAGER 5-01-1991 | 285000 | 25000 | 30 12882 _| SHIVANSH. MANAGER 09-06-1991 | 2450.00 nun_| 10 ‘e888 | SCOTT (ANALYST 09-12-1992 | 300000 | 15000 | 10 = AMIR PRESIDENT 7-11-1991 | 5000.00 wu | 20 ‘e844 KULDEEP SALESMAN 08-04-1992 | 1500.00 000 | 30) {@) Give the command to insert the record into the EMP table: Ang, insert into emp values(#369SMITH,/CLERK, 18-12-1990;1050,200,10; 1b) Write a query to display EmpName arid Sal of employees whose salary is areater than orequal t0 2200. ns. select empname, sal from emp where sal>=2200; {@) White a query to display details of employees who are not gettin ‘Ans, select * from emp where comm is NULL: (a) Waite 9 query to display employee name and salary of those ‘employees who don't have their salary in the range of 2500 to 4000, ‘Ans, select empname, sal from emP ‘Where sal not between 2500 and 4000: te) ite a query to display the name of employee whose name contains “ ‘ascending order of employee names: 19 commission. as thied alphabet in ‘Ans. select empname From emp Were empname like". -A%6" order by empnamet 1d commission of employees as (© Display the sum of salary an commission. [Ang select sal+comm As "To! (9) Show the average salary for all dearim ts al) From emp Group by aeptid Havind count 5: =Total Incentive" who are getting 1p where comm is NOT NULL: al Incentive” From er th more than § working people. ents wit Ans. select aval ‘Scanned with CamScanner (h) Ans. (i) Ans, 0 Ans. (ky Ans. wo Ans. (m) Ans. (n) Ans. (0) Ans. ® Ans. @ Ans. G) Ans. Display the distinct designation offered by the Organization. select distinct designation from emp; Display the names of employees who joined on or after 01/05/1991. Select empname From emp where DOJ>='1991/05/01'; Display the employee records in order by DOJ. select * From emp Order by DOJ; Display the maximum salary of employees in each Department. select max(sal) From emp Group by department; Update all the records as add ‘Mr.’ with EmpName. update emp set EmpName=concat('Mr,EmpName); Display the names of Employees who are working as salesman. select empname From EMP, where Designation = “Salesman”; Drop the emp table. drop table emp; Delete the records of all those employees who are working as clerk. delete from emp where designation="CLERK"; Increase the salary of manageis by 15%. update emp set sal= sal + 0.15*sal where designatio! Show details of employees who joined in the year 1991. select * from emp where year(DOJ)=1991; Delete the records of all those employees who are working as “SALESMAN” with salary-more than 1500. delete from emp where designation="SALESMAN" and sal>150¢ ‘Manager’; ‘Scanned with CamScanner,

You might also like