join重复行太多

vyu0f0g1  于 2021-07-29  发布在  Java
关注(0)|答案(2)|浏览(306)

列出在零售业或餐饮业工作的员工(名字和姓氏在同一列)。包括他们工作的建筑和商店类型。
这就是我所拥有的。每当我运行它,一切都会重复,所以现在有超过一百行了。有人能帮我吗?
编辑

SELECT CONCAT(first_name, ' ',last_name) AS "Employee", shop_type AS "Shop Type", Building_Assigned AS "Building Name"
FROM employees
FULL OUTER JOIN Shops 
ON employees.first_name = Shops.shop_type 
FULL OUTER JOIN buildings
ON employees.last_name = buildings.Building_Assigned
WHERE Shops.shop_type is NOT NULL OR employees.first_name IS NOT NULL OR employees.last_name IS NOT NULL OR buildings.Building_Assigned IS NOT NULL

我为此尝试了各种连接,以使这项工作,并给我的输出我想要的,但每当我这样做,例如,完整的外部连接返回一个商店类型和建筑名称为空,内部连接和连接只返回列的名称。其他的都返回空值。有没有人能帮我解决这个问题?

qvsjd97n

qvsjd97n1#

你必须使用 JOIN 所需输出的语法。
标准示例

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name
INNER JOIN table3
on table2.column_name2 = table3.column_name2;

尝试按上述方式连接表,您将得到输出。

ht4b089n

ht4b089n2#

内部联接必须用于连接数据的列。例如:

SELECT 
    CONCAT(first_name, '  ', last_name) AS Employee,
    shop_type AS "Shop Type", Building_Assigned AS "Building Name"
FROM employees e
    Shops s on e.Location=s.ShopID
    buildings b on b.BuildingID=s.BuildingID

你必须能够连接这些表。

相关问题