gpt4 book ai didi

sql-server - 双选择语句问题,返回多行,子查询返回超过 1 个值

转载 作者:行者123 更新时间:2023-12-02 02:15:34 25 4
gpt4 key购买 nike

好的,开始吧,我有 3 个表:

accounts             ( account_id,      employee_id, account_name )
projects ( project_id, project_name )
project_distribution ( distribution_id, employee_id, project_id )

如果我有来自 project_distribution 表的项目 ID,我想做的是从项目表返回项目名称。所以,假设我有 employee_id,我要进入 project_distribution 并进行选择,我获取 project_id 的 2 个值,id 1 和 2,我如何在不执行 2 个查询或语句的情况下返回这两个 ID 的 project_names 或者它们是如何正确调用的,这是我的错误选择语句。

SELECT project_name
FROM projects
WHERE project_id = ( SELECT project_id
FROM project_distribution
WHERE employee_id = ( SELECT employee_id
FROM accounts
WHERE account_name = 'tbogdan'
)
);

oufcorse 我将从 project_distribution 中获得 2 个值,以及一个“子查询返回超过 1 个值”错误,我该如何解决这个问题,并使其正常工作?如果需要更多信息,请询问...抱歉含糊不清的描述...

最佳答案

尝试这样的事情......

SELECT projects.project_name 
FROM projects
INNER JOIN project_distribution ON (projects.project_id = project_distribution.project_id)
INNER JOIN accounts ON (project_distribution.employee_id = accounts.employee_id)
WHERE accounts.employee_id = 'tbogdan'

关于sql-server - 双选择语句问题,返回多行,子查询返回超过 1 个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10870513/

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