我如何链接一组“执行的服务” mySQL 数据库中的我的员工?

发布于 2024-11-05 09:53:02 字数 103 浏览 0 评论 0原文

我目前有一个员工数据库,将在我们的网站上显示员工的联系信息。我还有一个包含我们公司提供的所有服务的数据库。每个员工都会提供一项或多项特定服务。我如何才能将每个员工与他们执行的不同服务联系起来?

I currently have an employee database that will display employee contact info on our website. I also have a database of all of the services our company offers. Each employee does one or more of those particular services. How could I link each employee to the different services they perform?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾挽 2024-11-12 09:53:02

您将添加第三个表作为联接表,其中将包含员工和服务表条目的键。每个员工在连接表中可能有几行,具体取决于他们提供的服务数量。

http://en.wikipedia.org/wiki/Junction_table

You would add a third table as a Join table that will contain keys to the employee and service table entries. Each employee may have several rows in the join table depending on the number of services they provide.

http://en.wikipedia.org/wiki/Junction_table

腻橙味 2024-11-12 09:53:02

您可以:

CREATE TABLE `employees_services`(
    `employee_id` INT NOT NULL ,
    `service_id` INT NOT NULL ,
    PRIMARY KEY (`employee_id`, `service_id`)
)

然后当您需要某个员工的所有服务时:

SELECT * FROM `employees` AS e
INNER JOIN `employees_services` AS es ON e.id = es.employee_id
WHERE ...

或当您需要所有员工的某项服务时:

SELECT * FROM `services` AS s
LEFT JOIN `employees_services` AS es ON s.id = es.service_id
WHERE ..

You can:

CREATE TABLE `employees_services`(
    `employee_id` INT NOT NULL ,
    `service_id` INT NOT NULL ,
    PRIMARY KEY (`employee_id`, `service_id`)
)

and then when you need all of the services for an employee:

SELECT * FROM `employees` AS e
INNER JOIN `employees_services` AS es ON e.id = es.employee_id
WHERE ...

or when you need to all the employees for a service:

SELECT * FROM `services` AS s
LEFT JOIN `employees_services` AS es ON s.id = es.service_id
WHERE ..

.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文