CompanyDB Problems page 1 of 3
Consider the employee database of Figure CompanyDB:
*************************************************
* employee (employee_name, street, city) *
* works (employee_name, company_name, salary) *
* company (company_name, city) *
* manages (employee_name, manager_name) *
*************************************************
Figure CompanyDB.
Using the course database, give an expression in SQL for each of the following queries. The expected results are indicated for each query.
a. Find the names of all employees who work for First Bank Corporation.
EMPLOYEE_NAME
--------------------
Ferris
Johnson
Laikin
Moira
Turner
b. Find the names and cities of residence of all employees who work for First Bank Corporation.
EMPLOYEE_NAME CITY
-------------------- --------------------
Ferris Westchester
Johnson Palo Alto
Laikin Culver City
Moira Kentwood
Turner Palo Alto
c. Find the names, street address, and cities of residence of all employees who work for First Bank Corporation and earn more than $10,000.
EMPLOYEE_NAME STREET CITY
-------------------- ------------------------------ --------------------
Ferris Loyola Westchester
Johnson Alma Palo Alto
Laikin Berryman Culver City
Moira Nancy Kentwood
Turner Alma Palo Alto
d. Find all employees in the database who live in the same cities as the companies for which they work.
EMPLOYEE_NAME
--------------------
August
Brooks
Curry
Hayes
Jones
Smith
e. Find all employees in the database who live in the same cities and on the same streets as do their managers.
EMPLOYEE_NAME
--------------------
Curry
Lindsay
Turner
Williams
f. Find all employees in the database who do not work for First Bank Corporation
EMPLOYEE_NAME
--------------------
Adams
August
Brooks
Curry
Glenn
Green
Hayes
Jones
Lindsay
Schmidt
Smith
Williams
Young
g. Find all employees in the database who earn more than every employee of Small Bank Corporation.
EMPLOYEE_NAME SALARY
-------------------- ---------
August 150000.00
Schmidt 120000.00
h. Assume that the companies may be located in several cities. Find all companies located in every city in which Small Bank Corporation is located
COMPANY_NAME
------------------------------
Small Bank Corporation
i. Find all employees who earn more than the average salary of all employees of their company.
EMPLOYEE_NAME
--------------------
Adams
August
Brooks
Ferris
Glenn
Green
Johnson
Laikin
j. Find the company that has the most employees. Show the company name and number of employees.
COMPANY_NAME COUNT(DISTINCT employee_name)
------------------------------ -----------------------------
First Bank Corporation 5
k. Find the company that has the smallest payroll.
COMPANY_NAME
------------------------------
Cathedral Software
l. Find those companies whose employees earn a higher salary, on average, than the average salary at First Bank Corporation.
COMPA.
CompanyDB Problemspage 1 of 3Consider the employee database of .docx
1. CompanyDB Problems page 1 of 3
Consider the employee database of Figure CompanyDB:
*************************************************
* employee (employee_name, street, city) *
* works (employee_name, company_name, salary) *
* company (company_name, city) *
* manages (employee_name, manager_name) *
*************************************************
Figure CompanyDB.
Using the course database, give an expression in SQL for each
of the following queries. The expected results are indicated for
each query.
a. Find the names of all employees who work for First Bank
Corporation.
EMPLOYEE_NAME
--------------------
Ferris
Johnson
Laikin
Moira
Turner
b. Find the names and cities of residence of all employees who
work for First Bank Corporation.
EMPLOYEE_NAME CITY
-------------------- --------------------
Ferris Westchester
Johnson Palo Alto
Laikin Culver City
2. Moira Kentwood
Turner Palo Alto
c. Find the names, street address, and cities of residence of all
employees who work for First Bank Corporation and earn more
than $10,000.
EMPLOYEE_NAME STREET CITY
-------------------- ------------------------------ --------------------
Ferris Loyola Westchester
Johnson Alma Palo Alto
Laikin Berryman Culver City
Moira Nancy Kentwood
Turner Alma Palo Alto
d. Find all employees in the database who live in the same cities
as the companies for which they work.
EMPLOYEE_NAME
--------------------
August
Brooks
Curry
Hayes
Jones
Smith
e. Find all employees in the database who live in the same cities
and on the same streets as do their managers.
EMPLOYEE_NAME
--------------------
Curry
Lindsay
3. Turner
Williams
f. Find all employees in the database who do not work for First
Bank Corporation
EMPLOYEE_NAME
--------------------
Adams
August
Brooks
Curry
Glenn
Green
Hayes
Jones
Lindsay
Schmidt
Smith
Williams
Young
g. Find all employees in the database who earn more than every
employee of Small Bank Corporation.
EMPLOYEE_NAME SALARY
-------------------- ---------
August 150000.00
Schmidt 120000.00
h. Assume that the companies may be located in several cities.
Find all companies located in every city in which Small Bank
Corporation is located
4. COMPANY_NAME
------------------------------
Small Bank Corporation
i. Find all employees who earn more than the average salary of
all employees of their company.
EMPLOYEE_NAME
--------------------
Adams
August
Brooks
Ferris
Glenn
Green
Johnson
Laikin
j. Find the company that has the most employees. Show the
company name and number of employees.
COMPANY_NAME COUNT(DISTINCT employee_name)
------------------------------ -----------------------------
First Bank Corporation 5
k. Find the company that has the smallest payroll.
COMPANY_NAME
------------------------------
Cathedral Software
l. Find those companies whose employees earn a higher salary,
on average, than the average salary at First Bank Corporation.
COMPANY_NAME
------------------------------
5. IBM
Integrated Data Systems
Multnomah Software
Small Bank Corporation
Sneakers
saugust-CompanyDB-DROP.sql
DROP TABLE IF EXISTS works
;
DROP TABLE IF EXISTS works2
;
DROP TABLE IF EXISTS manages
;
DROP TABLE IF EXISTS manages2
;
DROP TABLE IF EXISTS company
;
DROP TABLE IF EXISTS company2
;
DROP TABLE IF EXISTS employee
;
DROP TABLE IF EXISTS employee2
;
__MACOSX/._saugust-CompanyDB-DROP.sql
6. saugust-CompanyDB.sql
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET
@[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET
@OLD_CHARACTER_SE[email protected]@CHARACTER_SE
T_RESULTS */;
/*!40101 SET
@[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
-- --------------------------------------------------------
--
-- Table structure for table `company`
--
CREATE TABLE IF NOT EXISTS `company` (
`company_name` varchar(30) NOT NULL DEFAULT '',
`city` varchar(20) DEFAULT NULL,
PRIMARY KEY (`company_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `company`
--
7. INSERT INTO `company` (`company_name`, `city`) VALUES
('Cathedral Software', 'San Francisco'),
('First Bank Corporation', 'Brooklyn'),
('IBM', 'San Jose'),
('Integrated Data Systems', 'Westchester'),
('Multnomah Software', 'Westchester'),
('Small Bank Corporation', 'Palo Alto'),
('Sneakers', 'Chicago');
-- --------------------------------------------------------
--
-- Table structure for table `company2`
--
CREATE TABLE IF NOT EXISTS `company2` (
`company_name` varchar(30) NOT NULL DEFAULT '',
`city` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`company_name`,`city`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `company2`
--
INSERT INTO `company2` (`company_name`, `city`) VALUES
('August Software', 'Westchester'),
('Cathedral Software', 'Palo Alto'),
('Cathedral Software', 'San Francisco'),
('Cathedral Software', 'Santa Clara'),
('First Bank Corporation', 'Brighton'),
('First Bank Corporation', 'Brooklyn'),
('IBM', 'San Jose'),
('IBM', 'Yorktown Heights'),
('Integrated Data Systems', 'Westchester'),