Advertisement
AmidamaruZXC

Untitled

Nov 9th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.26 KB | None | 0 0
  1. CREATE TABLE `employee` (
  2.   `username` varchar(45) NOT NULL,
  3.   `password` varchar(45) DEFAULT NULL,
  4.   `fullname` varchar(45) DEFAULT NULL,
  5.   `email` varchar(45) DEFAULT NULL,
  6.   `position` varchar(45) DEFAULT NULL,
  7.   `retired` tinyint(1) DEFAULT NULL,
  8.   `company` varchar(45) DEFAULT NULL,
  9.   PRIMARY KEY (`username`));
  10.  
  11. CREATE TABLE `client` (
  12.   `longname` varchar(45) DEFAULT NULL,
  13.   `shortname` varchar(45) DEFAULT NULL,
  14.   `inn` double NOT NULL,
  15.   `email` varchar(45) DEFAULT NULL,
  16.   PRIMARY KEY (`inn`));
  17.  
  18. CREATE TABLE `project` (
  19.   `name` varchar(45) NOT NULL,
  20.   `startdate` datetime DEFAULT NULL,
  21.   `enddate` datetime DEFAULT NULL,
  22.   `clientinn` double DEFAULT NULL,
  23.   `companyname` varchar(45) DEFAULT NULL,
  24.   PRIMARY KEY (`name`));
  25.  
  26.  
  27.  
  28.  
  29.  
  30. CREATE TABLE `company` (
  31.   `name` VARCHAR(45) NOT NULL,
  32.   PRIMARY KEY (`name`));
  33.  
  34. CREATE TABLE `task` (
  35.   `id` int NOT NULL,
  36.   `project` varchar(45) DEFAULT NULL,
  37.   `endtime` datetime DEFAULT NULL,
  38.   `suspended` tinyint(1) DEFAULT NULL,
  39.   `employee` varchar(45) DEFAULT NULL,
  40.   `eversuspended ` tinyint(1) DEFAULT NULL,
  41.   PRIMARY KEY (`id`));
  42.  
  43. Exercise 2.
  44. select username, sum(endtime - startdate) over (partition by username) from (select * from employee e inner join task t on t.employee = e.username inner join project p on t.project = p.name where e.company = 'GIVEN' and month(p.startdate) >= 12 and month(t.endtime) <= 12 and t.endtime <> NULL) sel;
  45. Exercise 3.
  46. select username, longname, sum(endtime - startdate) over (partition by username, inn) from (select * from employee e inner join task t on t.employee = e.username inner join project p on t.project = p.name inner join (select clnt.longname, clnt. inn from client clnt) clnt on clnt.inn = p.clientinn where e.company = 'GIVEN' and month(p.startdate) >= 12 and month(t.endtime) <= 12 and t.endtime <> NULL) s;
  47.  
  48. Exercise 5.
  49. select * from employee e inner join company c on e.company = c.name where not exists (select * from project p where p.companyname = c.name and year(p.startdate) <= 2007 and year(p.enddate) >= 2007 and not exists (select * from task t where t.project = p.name and t.employee = e.username));
  50. Exercise 6.
  51. select p.clientname, p.name from project p where not exists(select * from task t where p.name = t.project and t.eversuspended = 0);
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement