realsdx

DBMS LAB 5

Mar 6th, 2020
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. 1. mysql> select count(e_name), location from employee, department where d_id=dept_id group by location;
  2. +---------------+----------+
  3. | count(e_name) | location |
  4. +---------------+----------+
  5. | 1 | L1 |
  6. | 2 | L2 |
  7. | 1 | L3 |
  8. | 1 | L4 |
  9. | 1 | L5 |
  10. | 1 | L6 |
  11. | 1 | L7 |
  12. | 3 | L8 |
  13. +---------------+----------+
  14. 8 rows in set (0.00 sec)
  15.  
  16. 2. mysql> select count(e_name) from employee inner join work_project inner join project on work_project.pro_id=project.p_id where eid=employee.emp_id AND email LIKE '%@gmail%' AND p_name="Campus Fire Alarm System";
  17. +---------------+
  18. | count(e_name) |
  19. +---------------+
  20. | 2 |
  21. +---------------+
  22. 1 row in set (0.00 sec)
  23.  
  24. 3.
  25. mysql> select * from employee where email NOT LIKE '%@gmail%' and email NOT LIKE '%@yahoo%';
  26. +--------+------+--------+------------+-----------------------+------------+------+--------+
  27. | emp_id | d_id | e_name | phone | email | birthday | sex | salary |
  28. +--------+------+--------+------------+-----------------------+------------+------+--------+
  29. | 5 | 6 | Rakesh | 9878765432 | rakesh@rediffmail.com | 1982-09-29 | M | 29000 |
  30. | 10 | 3 | Nilesh | 9854562123 | | 1983-10-12 | M | 39800 |
  31. | 13 | 8 | Malay | | | 0000-00-00 | M | 0 |
  32. +--------+------+--------+------------+-----------------------+------------+------+--------+
  33. 3 rows in set (0.00 sec)
  34.  
  35. 4. mysql> select e_name from employee where birthday LIKE '%9%';
  36. +-----------+
  37. | e_name |
  38. +-----------+
  39. | Aadarsh |
  40. | Aalam |
  41. | Gajendra |
  42. | Chiranjit |
  43. | Rakesh |
  44. | Anjali |
  45. | Bikash |
  46. | Nilesh |
  47. | Tapas |
  48. | Abhishek |
  49. +-----------+
  50. 10 rows in set, 1 warning (0.00 sec)
  51.  
  52. 5. mysql> select e_name from employee where month(birthday) not in (02,10);
  53. +----------+
  54. | e_name |
  55. +----------+
  56. | Rakesh |
  57. | Anjali |
  58. | Bikash |
  59. | Abhishek |
  60. | Malay |
  61. +----------+
  62. 5 rows in set (0.00 sec)
  63.  
  64. 6. mysql> select e_name, phone, email, sex, salary from employee inner join work_project on employee.emp_id=work_project.eid inner join project on work_project.pro_id=project.p_id where year(s_date)=2012;
  65. +-----------+-------------+---------------------+------+--------+
  66. | e_name | phone | email | sex | salary |
  67. +-----------+-------------+---------------------+------+--------+
  68. | Aadarsh | 9878765432 | adarsh@gmail.com | M | 30000 |
  69. | Chiranjit | 033-2345434 | chiranjit@yahoo.com | M | 31000 |
  70. +-----------+-------------+---------------------+------+--------+
  71. 2 rows in set (0.00 sec)
  72.  
  73. 7. mysql> select sum(salary) from employee inner join department on dept_id=d_id where location in ("L1","L4");
  74. +-------------+
  75. | sum(salary) |
  76. +-------------+
  77. | 70000 |
  78. +-------------+
  79. 1 row in set (0.00 sec)
  80.  
  81. 8. mysql> select * from employee where salary>30000 and salary<35000;
  82. +--------+------+-----------+-------------+---------------------+------------+------+--------+
  83. | emp_id | d_id | e_name | phone | email | birthday | sex | salary |
  84. +--------+------+-----------+-------------+---------------------+------------+------+--------+
  85. | 4 | 5 | Chiranjit | 033-2345434 | chiranjit@yahoo.com | 1987-10-28 | M | 31000 |
  86. | 6 | 8 | Anjali | 89654534 | anjali@yahoo.com | 1986-11-26 | F | 32500 |
  87. | 12 | 8 | Abhishek | 9834323456 | abhishek@yahoo.com | 1982-03-20 | M | 34000 |
  88. +--------+------+-----------+-------------+---------------------+------------+------+--------+
  89. 3 rows in set (0.00 sec)
  90.  
  91. 9. mysql> select datediff(curdate(), birthday)/365 as YEARS_OLD from employee where e_name="Tapas";
  92. +-----------+
  93. | YEARS_OLD |
  94. +-----------+
  95. | 34.4137 |
  96. +-----------+
  97. 1 row in set (0.00 sec)
  98.  
  99.  
  100. 10.mysql> select * from employee where email LIKE '%gmail%';
  101. +--------+------+----------+-------------+--------------------+------------+------+--------+
  102. | emp_id | d_id | e_name | phone | email | birthday | sex | salary |
  103. +--------+------+----------+-------------+--------------------+------------+------+--------+
  104. | 1 | 1 | Aadarsh | 9878765432 | adarsh@gmail.com | 1987-02-19 | M | 30000 |
  105. | 3 | 4 | Gajendra | 0343-234565 | gajendra@gmail.com | 1983-02-09 | M | 40000 |
  106. | 7 | 2 | Bikash | 8965755467 | bikash@gmail.com | 1983-04-28 | M | 40100 |
  107. | 11 | 7 | Tapas | 0343-234345 | tapas@gmail.com | 1985-10-15 | M | 25500 |
  108. +--------+------+----------+-------------+--------------------+------------+------+--------+
  109. 4 rows in set (0.00 sec)
Add Comment
Please, Sign In to add comment