Advertisement
korenizla

sap_task2

Aug 4th, 2023
1,395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.45 KB | None | 0 0
  1. CREATE TABLE employees (
  2.   id INT,
  3.   name VARCHAR(100),
  4.   department VARCHAR(100),
  5.   salary INT,
  6.   employ_id INT
  7. );
  8. INSERT INTO employees (id, name, department, salary, employ_id)
  9. VALUES
  10.     (1001,  'Ivanov',   'SAPIENS',  100000, 1001),
  11.     (1002,  'Petrov',   'SAPIENS',  100000, 1001),
  12.     (1003,  'Sidorov',  'TECHNOLOGIES', 130000, 1001),
  13.     (1004,  'Korotkov', 'TECHNOLOGIES', 120000, 1001),
  14.     (1005,  'Filev',    'SAPIENS',  90000,  1001),
  15.     (1006,  'Smirnov',  'REVOLT',   125000, 1001),
  16.     (1007,  'Godov',    'REVOLT',   125000, 1001);  
  17.  
  18. CREATE TABLE business_trip (
  19.   id INT,
  20.   employ_id INT,
  21.   dep_date DATE,
  22.   arriv_date DATE,
  23.   trav_expens INT
  24. );
  25. INSERT INTO business_trip (id, employ_id, dep_date, arriv_date, trav_expens)
  26. VALUES
  27.     (2001,  1001,   '2014-01-01',   '2014-01-10',   2000),
  28.     (2002,  1001,   '2015-01-01',   '2015-01-10',   3000),
  29.     (2003,  1001,   '2015-02-01',   '2015-03-10',   1500),
  30.     (2004,  1001,   '2015-06-01',   '2015-07-10',   2900),
  31.     (2005,  1001,   '2015-07-01',   '2015-08-10',   3600),
  32.     (2006,  1001,   '2016-01-01',   '2016-01-10',   5000),
  33.     (2007,  1001,   '2016-04-01',   '2016-06-10',   1000),
  34.     (2008,  1001,   '2016-07-01',   '2016-08-10',   5700),
  35.     (2009,  1001,   '2017-01-01',   '2017-01-10',   2100),
  36.     (2010,  1001,   '2017-03-01',   '2017-04-10',   5000);
  37.  
  38. SELECT SUM(b.trav_expens) AS SUM_TRAV_EXPENS
  39. FROM employees AS e LEFT JOIN business_trip AS b
  40. ON e.employ_id = b.employ_id
  41. WHERE e.salary > 90000 AND b.dep_date >= '2015-06-01';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement