The document discusses SQL queries on two database tables:
1) A 'loan_accounts' table with queries to create/insert/update/delete records and columns.
2) An 'items' table with queries to create/insert/update records and display records based on conditions.
Various SQL queries are listed to perform operations like selecting, updating, deleting records and columns on the tables based on different conditions.
The document discusses SQL queries on two database tables:
1) A 'loan_accounts' table with queries to create/insert/update/delete records and columns.
2) An 'items' table with queries to create/insert/update records and display records based on conditions.
Various SQL queries are listed to perform operations like selecting, updating, deleting records and columns on the tables based on different conditions.
The document discusses SQL queries on two database tables:
1) A 'loan_accounts' table with queries to create/insert/update/delete records and columns.
2) An 'items' table with queries to create/insert/update records and display records based on conditions.
Various SQL queries are listed to perform operations like selecting, updating, deleting records and columns on the tables based on different conditions.
1. consider a database “loans” with the following table
table: loan_accounts accno cust_name loan_amount installments int_rate start_date 1 r.k.gupta 300000 36 12.00 2009-07-19 2 s.p.sharma 500000 48 10.00 2008-03-22 3 k.p.jain 300000 36 null 2007-03-08 4 m.p.yadav 800000 60 10.00 2008-12-06 i. create the table loan_accounts by applying “primary key” on accno column and ‘not null’ on cust_name create table loan_accounts(accno int(1) primary key, cust_name varchar(20) not null, loan_amount int(10), installments int(2), int_rate float(4,2), start_date date);
insert into loan_accounts values (1,”r.k.gupta”,3000000,36,12,00,”2009-07-19”);
like this insert all other values;
for entry of null in third column
insert into loan_accounts(accno,cust_name,loan_amount,installment,start_date) values (3,”k.p.jain”,3000000,36,”2007-03-08”);
ii. write a sql query that display customer details whose interest rate is null? select * from loan_accounts where int_rate is null; iii. write a sql query to update start_date as ‘2002-12-31’ whose accno is 3? update table loan_accounts set start_date=”2002-12-31” where accno =3; iv. write a sql query to display only year from start_date of loans_accounts relation? select year(start_date) from loan_accounts; v. write sql query to display maximum and minimum installment. select max(installment),min(installment) from loan_accounts; vi. write a sql query to update installments to 70 whose accno is ‘1’? update table loan_accounts set installment=70 where accno =1; vii. write a sql query to delete the entire table’s data? Delete from loan_accounts; viii. write a sql query that updates loan amount by 15%. update table loan_accounts set loan_amount = loan_amount + (loan_amount*0.15); ix. write a sql query to add a column to the table “end_date”? alter table loan_accounts add column end_date date; x. write a sql query to increase the interest rate by 0.5% for all the loans for which the loan amount is more than 400000. update table loan_accounts set loan_amount = loan_amount + (loan_amount*0.05) where loan_amount>400000; xi. write a sql query to delete a column to the table “start_date”? alter table loan_accounts drop column start_date;
part 2 1. consider the following “items” table icode name category rate 1001 masala dosa south indian 60 1002 vadasambar south indian 40 1003 idlisambar south indian 40 2001 chow mein chinese 80 (i) create above table by applying primary key and not null on icode and name respectively. create table items(icode int(4) primary key, name varchar(20) not null, category varchar(20), rate int(2));
insert into items values (1001,”masala dosa”,”south indian”,60);
like this insert all other values;
(ii) write a sql query that display all items details whose name starts with ‘m’ select * from items where name like(“m%”); (iii) write a sql query that increases all rates by 10 percent update items set rate=rate+(rate*0.1); (iv) write a sql query to display items details whose rate is in between 60 to 80. select * from items where rate between 60 and 80; (v) write a sql query to display average rate of all items. select avg(rate) from items;