Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- create database mycompany;
- go
- use mycompany;
- create table locations (
- id int,
- city varchar(255),
- country varchar(255),
- addr varchar(255)
- primary key (id)
- )
- create table employee (
- id int,
- boss int,
- name varchar(255),
- division varchar(255),
- location_id int,
- primary key (id),
- foreign key (location_id) references locations (id)
- )
- create table wages (
- employee_id int,
- wage int
- foreign key (employee_id) references employee (id),
- )
- insert into locations (id, country, city, addr) values
- (1, 'canada', 'toronto', 'mccowan'),
- (2, 'saudi arabia', 'madina', 'sultana'),
- (4,'canada', 'toronto', 'brimley'),
- (22, 'usa', 'washington', 'pennsylvania av')
- insert into employee (id, boss, name, division, location_id) values
- (1, NULL, 'joe', 'management', 2),
- (44, 1, 'ryan habibi', 'IS', 1),
- (11, 44, 'abdullah', 'IS', 4),
- (2, 11, 'tommy', 'management', 22),
- (3, 11, 'dan', 'IT', 4),
- (5, 2, 'zair', 'janitorial services', 1)
- insert into wages (employee_id, wage) values
- (1, 4000),
- (44, 12000),
- (11, 200),
- (2, 8),
- (3, 20),
- (5, 1000)
- */
- select employee.id, employee.name, wages.wage
- from wages join employee on wages.employee_id = employee.id
- where wages.wage = (select max(wage) from wages)
- select employee.location_id, count(*)
- from employee join locations on employee.location_id = locations.id
- group by employee.location_id
- select count(*),locations.city
- from employee join locations on employee.location_id = locations.id
- group by locations.city
- select boss , count(*)
- from employee as e1
- group by boss
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement