加入SQL SERVER 2012 [英] Join in SQL SERVER 2012
本文介绍了加入SQL SERVER 2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我有两个表作为A,B。表A保存我的类别名称,表B保存
我的fk_tbl_A,时间,机器名。
我想计算时间,我用过每台机器并按fk_abl_A分组
我写了下面的SQL 2012中的代码:
Hello
I have two table as A,B .Table A holds my category names and table B holds
my fk_tbl_A ,time ,machine name.
I want to calculate the time ,which I have used for each machine and grouped by fk_abl_A
I wrote the below code in SQL 2012:
select sum(cast(a.during_time as int)) from dbo.sabt_bazdid as a
join dbo.ability as b
on a.fk_operator_ability = b.id
Group by a.fk_operator_ability
代码在这里工作得很好,但是当我想显示类别的名称时在表A中,
Sql显示错误。
The code working well here but when I want to show the names of the category in table A ,
Sql shows error.
select b.name , sum(cast(a.during_time as int)) from dbo.sabt_bazdid as a
join dbo.ability as b
on a.fk_operator_ability = b.id
Group by a.fk_operator_ability
请帮我解决问题
谢谢。
Please help me to solve problem
Thanks.
推荐答案
你会遇到这样的错误:
You would have encountered error like this:
Column 'b.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
尝试更改此:
Try change this:
Group by a.fk_operator_ability
to
to
Group by a.fk_operator_ability, b.name
希望有所帮助。
Hope it helps.
这篇关于加入SQL SERVER 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文