sql报错:该列既不包含在聚合函数中
table1字段:brch,workday,currtype,amounttable2字段:number,nameselecttable1.brch,table2.nam...
table1字段:brch,workday,currtype,amount
table2字段:number,name
select table1.brch,table2.nam,table1.amount from table1 INNER JOIN
table2 ON table1.brch=brch.number where table1.brch=table2.number
and table1.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"') and table1.currtype ='"& currtype & "'
group by table1.brch order by table1.brch
Microsoft OLE DB Provider for SQL Server (0x80040E14)
列 'table1.brch' 在选择列表中无效,因为该列既不包含在聚合函数中,也不
包含在 GROUP BY 子句中。 展开
table2字段:number,name
select table1.brch,table2.nam,table1.amount from table1 INNER JOIN
table2 ON table1.brch=brch.number where table1.brch=table2.number
and table1.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"') and table1.currtype ='"& currtype & "'
group by table1.brch order by table1.brch
Microsoft OLE DB Provider for SQL Server (0x80040E14)
列 'table1.brch' 在选择列表中无效,因为该列既不包含在聚合函数中,也不
包含在 GROUP BY 子句中。 展开
4个回答
展开全部
select table1.brch,table2.nam,table1.amount from table1 INNER JOIN
table2 ON table1.brch=brch.number where table1.brch=table2.number
and table1.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"') and table1.currtype ='"& currtype & "'
group by table1.brch order by table1.brch
改成
select table1.brch,table2.nam,table1.amount from table1 INNER JOIN
table2 ON table1.brch=brch.number where table1.brch=table2.number
and table1.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"') and table1.currtype ='"& currtype & "'
group by table1.brch,table2.nam,table1.amount order by table1.brch
就不会报错。但是他可能实现不了你要的功能。。
table2 ON table1.brch=brch.number where table1.brch=table2.number
and table1.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"') and table1.currtype ='"& currtype & "'
group by table1.brch order by table1.brch
改成
select table1.brch,table2.nam,table1.amount from table1 INNER JOIN
table2 ON table1.brch=brch.number where table1.brch=table2.number
and table1.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"') and table1.currtype ='"& currtype & "'
group by table1.brch,table2.nam,table1.amount order by table1.brch
就不会报错。但是他可能实现不了你要的功能。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有group by 子句的话,跟在select后面的选择列表只能有两种,一种是在group by 子句中包含的字段,不种是sum(),avg(),max(),min()之内的用计算得到的列。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a.brch,b.name,sum(a.amount)
from table1 a
INNER JOIN
table2 b
ON a.brch=b.number
where a.brch=b.number
and a.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"')
and a.currtype ='"& currtype & "'
group by a.brch,b.name
order by a.brch
table1.amount 改成sum(table1.amount)或者count(table1.amount)
另外group by 后面改成group by a.brch,b.name;还有你一开始name字段少写了一个e。
group by 是对聚合函数的归类,你概念还没搞清楚嘛。如果不要聚合就不用加group by 。
beginday,endday,currtype 这3个变量需要申明并赋值的,你知道的吧?
from table1 a
INNER JOIN
table2 b
ON a.brch=b.number
where a.brch=b.number
and a.workday between convert(datetime,'"&beginday&"') and
convert(datetime,'"&endday&"')
and a.currtype ='"& currtype & "'
group by a.brch,b.name
order by a.brch
table1.amount 改成sum(table1.amount)或者count(table1.amount)
另外group by 后面改成group by a.brch,b.name;还有你一开始name字段少写了一个e。
group by 是对聚合函数的归类,你概念还没搞清楚嘛。如果不要聚合就不用加group by 。
beginday,endday,currtype 这3个变量需要申明并赋值的,你知道的吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
还有字段未加入到 GROUP BY 语句后面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询