Romkapost
Новичок
Интересное тестовое задание с разрабткой структуры MySQL
Всем привет!
Потенциальный заказчик подкинул интересное тестовое задание на PHP+MySQL,я не прошу его решить за меня,но предлагаю обсудить возможную структуру базы.
Task: DB schema of a system which is currently working as follow.
Employees:- different levels/types of user in organisation like CEO, administrator, Manager, Supervisiors, workers etc etc
Departments
HR, IT, Health, Accounts etc etc
Each employee is working in multiple roles like user "ABC" is working manager as well as worker. It is also possible that manger of "ERT" dept and "SGY" can assign duty to worker "XYZ"
1 Please design a DB schema which handles this situation in a most efficient way. Please design most suitable and best way to handle all these activites. and also poplule some data in DB and design SQL queries which gives us following results
1.1 Show managers who are also reporting to other managers of other departments.
1.2 Show all employees who have more than 1 managers.
1.3 Show all employees who don't have any managers.
Я сделал следующую структуру:
Особую трудность как я думаю представляет организация сввязи между сотрудниками,была идея использовать древовидную структуру в таблице `employees`,однако ведь работник может управлятся несколькими менеджерами,поэтому поле parent_id я думаю не подходит,тогда решил создать промежуточную таблицу managers,но что то смущает.
Какие будут мысли?
Всем привет!
Потенциальный заказчик подкинул интересное тестовое задание на PHP+MySQL,я не прошу его решить за меня,но предлагаю обсудить возможную структуру базы.
Task: DB schema of a system which is currently working as follow.
Employees:- different levels/types of user in organisation like CEO, administrator, Manager, Supervisiors, workers etc etc
Departments
HR, IT, Health, Accounts etc etc
Each employee is working in multiple roles like user "ABC" is working manager as well as worker. It is also possible that manger of "ERT" dept and "SGY" can assign duty to worker "XYZ"
1 Please design a DB schema which handles this situation in a most efficient way. Please design most suitable and best way to handle all these activites. and also poplule some data in DB and design SQL queries which gives us following results
1.1 Show managers who are also reporting to other managers of other departments.
1.2 Show all employees who have more than 1 managers.
1.3 Show all employees who don't have any managers.
Я сделал следующую структуру:
Код:
#
# Структура таблицы `departments`
#
CREATE TABLE `departments` (
`dep_id` int(11) NOT NULL auto_increment,
`dep_title` varchar(64) default NULL,
PRIMARY KEY (`dep_id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;
# --------------------------------------------------------
#
# Структура таблицы `employees`
#
CREATE TABLE `employees` (
`empl_id` int(11) NOT NULL auto_increment,
`empl_type_id` int(11) NOT NULL default '0',
`dep_id` int(11) NOT NULL default '0',
`empl_name` varchar(64) default NULL,
PRIMARY KEY (`empl_id`,`empl_type_id`,`dep_id`)
) TYPE=MyISAM ROW_FORMAT=DYNAMIC AUTO_INCREMENT=5 ;
# --------------------------------------------------------
#
# Структура таблицы `employees_type`
#
CREATE TABLE `employees_type` (
`empl_type_id` int(11) NOT NULL auto_increment,
`empl_type_title` varchar(64) NOT NULL default '',
PRIMARY KEY (`empl_type_id`),
UNIQUE KEY `empl_type_id` (`empl_type_id`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;
# --------------------------------------------------------
#
# Структура таблицы `managers`
#
CREATE TABLE `managers` (
`parent_id` int(11) default NULL,
`child_id` int(11) default NULL
) TYPE=MyISAM;
Какие будут мысли?