gpt4 book ai didi

mysql - 对于这个 MySQL 查询有更好的方法吗?

转载 作者:行者123 更新时间:2023-11-29 09:08:10 26 4
gpt4 key购买 nike

以下查询查找所有商店的董事。我认为有一个更简单的解决方案,我更喜欢使用它。谢谢。

SELECT s.ShopID, (EmployeeName+' '+EmployeeSurname) AS FullName FROM shop AS s
JOIN WorksOn AS w ON s.ShopID = w.ShopID
JOIN employee AS e ON w.EmployeeID = e.EmployeeID
JOIN director AS d ON e.EmployeeID = d.EmployeeID

表格

employee : EmployeeID, EmployeeName,EmployeeSurname
shop: ShopID, Name, Address
WorksOn: EmployeeID, ShopID
director: EmployeeID

最佳答案

这是一个非常简单的查询。根据您提供的信息,我没有看到任何更简单的事情。

请原谅。是的,您可以通过 2 个连接来完成:

SELECT 
w.ShopID, (EmployeeName+' '+EmployeeSurname) AS FullName
FROM
WorksOn AS w
JOIN employee AS e ON w.EmployeeID = e.EmployeeID
JOIN director AS d ON e.EmployeeID = d.EmployeeID

关于mysql - 对于这个 MySQL 查询有更好的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6457208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com