SQL Sub查询问题 [英] SQL Sub query problem
本文介绍了SQL Sub查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此SQL查询出现以下错误:
This SQL Query arises the following error :
"
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
请解释我的子查询及其用法:
" Please explain me subquery and its use :
select (select L.lineName from tblLine L inner join TERMSHR..tblCompany C on L.CompanyCode=C.CompanyCode where L.Location='Mirpur'
) as LineName from tblDayMonthProductionEntry where ProductionDate between '1-Aug-2013' and '5-Aug-2013' and Location='Mirpur'
推荐答案
此查询是子查询。它返回多行。当您将其放在括号内并将其命名为带有As
关键字的列时,您将其指定为子查询。
This query is the subquery. It returns more than one row. When you put it inside parenthesis and named it as a column with theAs
keyword, you designated it as a subquery.
(select L.lineName from tblLine L inner join TERMSHR..tblCompany C on L.CompanyCode=C.CompanyCode where L.Location='Mirpur') As LineName
看到表的DDL并了解输出要求,很难就解决方案提出建议。
Without seeing the DDL for the tables and understanding the output requirements, it is difficult to advise you on a solution.
问题是你的查询有多个结果,每个结果必须在他的自己的结果行。
您的查询试图将所有结果排成一行。
此示例可以帮助您。
选择lineName
From(从tblLine L中选择L.lineName
内连接TERMSHR..tblCompany C on L.CompanyCode = C. CompanyCode
其中L.Location ='Mirpur'
)如LineName
其中ProductionDate介于'2013年8月1日'和'5-之间2013年8月'和位置='Mirpur'
The problem is that your query has multiple results, and each result must be in his own result row.
Yor query is trying to get all results in a unique row.
This sample can help you.
Select lineName
From (select L.lineName from tblLine L
inner join TERMSHR..tblCompany C on L.CompanyCode=C.CompanyCode
Where L.Location='Mirpur'
) as LineName
Where ProductionDate between '1-Aug-2013' and '5-Aug-2013' and Location='Mirpur'
这篇关于SQL Sub查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文