Q. With reference to following relations PERSONAL and JOB answer the questions that follow:

Create following tables such that Empno and Sno are not null and unique, date of birth is after '12-Jan-1960', name is never blank, Area and Native place is valid, hobby, dept is not empty, salary is between 4000 and 10000.


Table: Personal

 
Empno Name Dobirth Native place Hobby
123 Amit 23-Jan-1965 Delhi Music
127 Manoj 12-dec-1976 Mumbai Writing
124 Abhai 11-aug-1975 Allahabad Music
125 Vinod 04-apr-1977 Delhi Sports
128 Abhay 10-mar-1974 Mumbai Gardening
129 Ramesh 28-oct-1981 Pune Sports
Table: job
 
Sno Area App_date Salary Retd_date Dept
123 Agra 25-jan-2006 5000 25-jan-2026 Marketing
127 Mathura 22-dec-2006 6000 22-dec-2026 Finance
124 Agra 19-aug-2007 5500 19-aug-2027 Marketing
125 Delhi 14-apr-2004 8500 14-apr-2018 Sales
128 Pune 13-mar-2008 7500 13-mar-2028 Sales

(a) Show empno, name and salary of those who have Sports as hobby.

(b) Show name of the eldest employee.

(c) Show number of employee area wise.

(d) Show youngest employees from each Native place.

(e) Show Sno, Name, Hobby and Salary in descending order of Salary.

(f) Show the hobbies of those whose name pronounces as 'Abhay'.

(g) Show the appointment date and native place of those whose name starts with 'A' or ends in 'd'.

(h) Show the salary expense with suitable column heading of those who shall retire after 20-jan-2006.

(i) Show additional burden on the company in case salary of employees having hobby as sports, is increased by 10%.

(j) Show the hobby of which there are 2 or more employees.

(k) Show how many employee shall retire today if maximum length of service is 20 years.

(l) Show those employee name and date of birth who have served more than 17 years as on date.

(m) Show names of those who earn more than all of the employees of Sales dept.

(n) Increase salary of the employees by 5% of their present salary with hobby as Music or they
have completed at least 3 years of service.

(o) Write the output of:

(i) Select distinct hobby from personal;
(ii) Select avg(salary) from personal, job where Personal.Empno = Job.Sno and Area in ('Agra',
'Delhi');
(iii) Select count(distinct Native_place) from personal.
(iv) Select name, max(salary) from Personal, Job where Personal.Empno = Job.Sno;

(p) Add a new tuple in the table Personal essentially with hobby as Music.

(q) Insert a new column email in Job table.

(r) Create a table with values of columns empno, name, and hobby.

(s) Create a view of Personal and Job details of those who have served less than 15 years.

(t) Erase the records of employee from Job table whose hobby is not Sports.

(u) Remove the table Personal.



Answer :-

(a)
Select empno , name , salary from personal , Job  where Empno =  Sno and Hobby = “Sports” ;

(b)
Select * from personal where (select min( dobirth ) from personal ) = dobirth ;

(c)
Select count(name ) , from Personal , Job where Empno = Sno group by Area ;

(d)

Select name from personal Group by Native-place Order by max(dobirth) ;

(e)
Select Sno,Name , Hobbay , Salary from Personal , Job where Empno = Sno order by Salary desc ;

(f)
Select Hobby from Personal where name = “Abhay” ;

(g)
Select App_date , Native -place from Personal , Job where Empno = Sno and Name like “A%” or name like “%r” ;

(h)
Select salary as ' salary expense' from personal P, job J where p.empno=J.sno AND retd_date< '20160120' ;

(i)

Select ( sum ( Salary ) * 0.10 ) as “Additional_burden” from Personal , Job where Empno = Sno and Hobby = “Sports” ;

(j)
Select Hobby from Personal group by hobby having Count(*) >= 2 ;

(k)
Select name from personal , job where empno = sno and ( curdate( ) - app_date ) >= 200000 ;

(l)

Select name , Dobrirth from personal , job where empno = Sno and ( curdate() - app_date ) > 170000 ;

(m) Select Name from Personal, Job where Empno = Sno and Dept = “Sales” Order by max( Salary) in ('Sales');

(n) Update Personal , job
set salary = salary + 0.05 * salary
where Empno = Sno and Hobby = “Music”
or ( curdate() - App_date ) >= 30000 ;

(o)

(i)

distinct hobby

Music

Writing

Sports

Gardening


(ii)

avg(salary)

6333.3333


(iii)

count(distinct Native_place)

4


(iv)

Name

Max(salary)

Vinod

8500

 
(p)
Insert into Personal (Hobby) values (135,"PathWalla", 20081990, "Lucknow" “Music”);

(q)
Alter table Job add column email char(100) ;

(r)
Create table new_table (Select Empno , name,Hobby from Personal);

(s)
Select * from personal , job where empno = sno and ( retd_date - app_date ) < 150000 ;

(t)

Delete from job, personal where empno = Sno and hobby < >  “Sports” ;

(u)
Drop Table Personal;

49 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. b,d,h and many mor ther are no proper solution for them

    ReplyDelete
    Replies
    1. Sorry, due to some problem in this page it is not readable. but do not worry it will fix very soon. : )

      Delete
    2. please update it very soon i literally need it as soon as possible but you have not updated from 5-6 months so do it fast please

      Delete
  2. some of the question does not have any answer

    ReplyDelete
  3. please post asap!

    ReplyDelete
  4. Please post remaining questions

    ReplyDelete
  5. l,m,n are missing

    ReplyDelete
  6. option d solution is wrong
    it can not be possible
    because with group by you can only display similar values of a field.

    ReplyDelete
    Replies
    1. It is correct. Please check it your MySQL.

      Delete
    2. yeah please provide an alternate for d

      Delete
    3. Create table newpersonal AS ( SELECT Native_place , max(dobirth) FROM personal GROUP BY Native_place );

      Select name, newdobirth as dob from Personal,newpersonal where Personal.dobirth=newpersonal.newdobirth;


      i actually did this after i got the error others can use this as an alternate method :)

      Delete
  7. M does not run and gives this error :ERROR 3029 (HY000): Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query.

    ReplyDelete
    Replies
    1. I think you enter wrong spelling so, please correct it.

      Delete
    2. same problem

      Delete
  8. Thanks for the answers.

    ReplyDelete
  9. Nice , thanks for the answer!!

    ReplyDelete
  10. Hlo... thankuu vry much for these solutions...really admire ur hard work...just bcs of u in m able to complete my assignment questions.....thankuu....

    ReplyDelete
  11. great job keep it up nd thnx a lot for solutions

    ReplyDelete
  12. Thank you... It would be really helpful for my exams 😇

    ReplyDelete
  13. Will the answer be correct if we don't write sno=empno in a)

    ReplyDelete
    Replies
    1. No, It will incorrect, because you are breaking jioning rule.

      Delete
  14. Thank you these solutions are very helpful for us ..pls continue this..again very very thanks

    ReplyDelete
  15. In o iv) answer is Vinod 8500
    Please correct

    ReplyDelete
    Replies
    1. Ok, I have corrected it. Thank you for telling mistake.

      Delete
  16. In t) delete from job, personal where empno= sno and .....

    ReplyDelete
    Replies
    1. Ok, I have corrected it. Thank you for telling mistake.

      Delete
    2. rather than using IS NOT
      <> use kr skte hai na???

      Delete
  17. In h) select salary as ' salary expense' from personal P, job J where p.empno=J.sno AND retd_date<'20-jan-2006'

    ReplyDelete
    Replies
    1. Ok, I have corrected it. Thank you for telling mistake.

      Delete
  18. Few are incorrect!!

    ReplyDelete
  19. Thanks For Great Solutions

    ReplyDelete
  20. Create following tables such that Empno and Sno are not null and unique, date of birth is after '12-Jan-1960', name is never blank, Area and Native place is valid, hobby, dept is not empty, salary is between 4000 and 10000.
    This question isnt answered

    ReplyDelete
  21. In (k) and (l) what is the logic of giving 200000 and 170000 in place of years?

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post