Vous êtes sur la page 1sur 2

>Display all the purchases made by all customers. SELECT * FROM purchases; >Update the quantity to 3 for customer_id=1003.

UPDATE purchase set quantity=3 WHERE cust_id=1003; >Add the hire_dt for Staff4 to today s date. UPDATE staff set hire_dt=sysdate WHERE staff_id=st4; >Display all the purchases whose total purchase has exceeded Rs.2000.00 SELECT * FROM purchase WHERE amount>20000.00; >Display all purchases where they have purchased more than one product (use qty column) where their total purchases exceeded Rs.2500.00 SELECT * FROM purchase WHERE quantity>1 and amount>2500.00; >Display only credit card details from card_details table. SELECT * FROM card_details WHERE card_type='credit'; >Display customers who has registered in the year 2011. SELECT cust_name FROM customers WHERE (to_char(registered_dt,'yyyy'))=2011; >Add some rows in customers table to have customers from Kolkata and display all customers who has registered between 2011 and 2012 and should be from Chennai and Kolkata. SELECT * FROM customers WHERE (to_char(reg_dt,'yyyy')=2011 or to_char(reg_dt,'yy yy')=2012) and (city='chennai' or city='kolkata'); >Display the stores in 2nd and 3rd floor. SELECT * FROM stores WHERE floor_no=3 or floor_no=3; >Display all staffs whose experience is less than one year. select * from staff where to_char(hire_dt,'yyyy')>=2011; >Add all data in customer table to new_cust (enquired customers) and also add fe w more customers to it. create table new_cust as select * from customers; insert into new_cust(cust_id,c ust_name,addr,city,phno,reg_dt)values (115,'dasan','ec','blore',9791097322,'12-s ep-2009'); >Delete any one newly added customer in new_cust (enquired customers). delete from new_cust where cust_id = (select cust_id from (select cust_id from e 21776798_new_cust minus select cust_id from e21776798_customer)); >Display the count of transactions done and unique customers id count. select count(amount),count(distinct cust_id) from transaction; >Identify count of customers who has joined 2 days back. select * from customers where to_char(reg_dt,'dd')=to_char(sysdate,'dd')-2; >Combine both customers and enquired_customers and identify which record is from Enquired_cust table and which is from Customer table. >>combining both tables and merging them into a new table named as empid_merge. sql>>create table e21776068_merge as select * from e21776068_customers union sel ect *from e21776068_new_cust; *merging the tables with entries different from each other sql>>select cust_id,'cust' from cust union select cust_id,'new_cust' where (sele ct * from cust minus select *from new_cust) union (select * from new_cust minus select * from cust);

>Find the number of floors in the mall. select count(distinct floor_no) from store; >Delete all staffs who joined before 2010. delete from staff where to_char(hire_dt,'yyyy')<2010; >Identify those customers whose phone number is not 10 digit. select cust_name from customers where length(ph_no)!=10; >Add 2 more attributes in customer table as first_name and last_name and update first and last name column using cust_nm attribute. Eg: If cust_nm is Ram Kumar , first_nm should have Ram and last_nm should have Kumar . >>alter table customers add(first_name varchar(10),last_name varchar(10)); >>update customers set(first_name,last_name)=select substr(cust_name,1,instr(cus t_name,' ')) fst_nm, substr(cust_name,instr(cust_name,' ')+1,length(cust_name)-i nstr(cust_name,' ')) lst_nm from new_cust ; >Identify staffs who joined in 2011 and their salary is less than 300000.00 per annum. select * from staff where to_char(hire_dt,'yyyy')=2011 and salary<300000.00; >Update the hire date to today for those where it is is missing update staff set hire_dt=sysdate where hire_dt is null;