[英]How to fix error: “Subquery returned more than 1 value”. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression
The full error is: 完整的错误是:
Subquery returned more than 1 value. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression
The query: 查询:
SqlConnection connect = Helper.GetCon;
string query = "select sum(amardate) as[All] ,"+
"(select amardate from Amar where insertdate='" +
DateTime.UtcNow.ToString("s") + "')as[Now]," +
"(select amardate from Amar where insertdate='" +
DateTime.UtcNow.AddDays(-1).ToString("s") + "')as[Last] From Amar";
SqlDataAdapter da = new SqlDataAdapter(query, connect);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
One or more of your subqueries returned multiple rows of data, in a context where it can only ever return one. 在一个子查询只能返回一个的上下文中,一个或多个子查询返回了多行数据。 eg you've got something like this happening: 例如,您正在发生以下情况:
1234 1121
sum(amardate) + 5678 AS now + 3141 AS last
9101 5161
where the 1234
, 1121
, etc... are the extra rows returned by the subquery. 其中, 1234
, 1121
,等等都是由子查询返回的额外行。 Now what does the DB do? 现在数据库做什么? It has no idea WHICH of those multiple values you want to add together. 它不知道您想将这些多个值加在一起。 It also can't just magically split this one row result into three new rows, because it has no idea HOW the split should occur. 它也不能仅仅将这一行结果神奇地拆分为三个新行,因为它不知道拆分应该如何进行。
You need to make sure the two subqueries can return only ONE result row, consisting of ONE single value. 您需要确保两个子查询只能返回一个由一个单一值组成的结果行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.