gpt4 book ai didi

SQL查询返回错误结果以获取部门

转载 作者:行者123 更新时间:2023-12-01 09:41:35 24 4
gpt4 key购买 nike

我有一个像这样的表 Department:

DepartmentName    City            NumberOfEmployees    Country
----------------------------------------------------------------
Abc California 100 USA
Xyz Chicago 200 USA
Lmn Sydney 300 Aus
Pqr Paris 400 France

技术:

TechnologyId    Name     DepartmentName 
----------------------------------------
1 Hadoop Abc
2 Hadoop Abc
3 Hadoop Xyz
4 Hadoop Lmn
5 Adobe Pqr
6 Adobe Lmn
7 Adobe Abc

这就是我想要做的:

  • 获取同时拥有 Hadoop 和 Adob​​e 的所有部门

查询:

SELECT 
Department.DepartmentName, Department.DepartmentName,
Department.DepartmentName, Department.DepartmentName,
Technologies.Name
FROM
Department
INNER JOIN
Technologies ON Department.DepartmentName = Technologies.DepartmentName
WHERE
(((Technologies.Name) IN ('Hadoop', 'Adobe')));

但这返回了错误的结果。

谁能帮我查询一下?

最佳答案

我会使用exists:

select d.*
from department d
where
exists (
select 1
from technologies t
where t.departmentname = d.departmentname and t.name = 'Hadoop'
)
and exists (
select 1
from technologies t
where t.departmentname = d.departmentname and t.name = 'Adobe'
)

有了 technologies(departmentname, name) 的索引,这应该是一个有效的选择。

关于SQL查询返回错误结果以获取部门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59803368/

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