问题描述
我想通过从医生桌上获取一个值来插入一个部门的全部医生。
我尝试了什么:
插入部门(Total_Doctor)
值((从部门Dep选择计数(*),医生做
其中Dep.De_ID = Do.De_ID
Group by Dep.Name
));
错误:
子查询返回的值超过1。
当子查询跟随=,!=,< < =,>,> =或当子查询用作表达式
I like to insert total doctors in a department by getting a value from doctor table.
What I have tried:
Insert into Department (Total_Doctor)
values (( Select Count(*) from department Dep, Doctor do
Where Dep.De_ID = Do.De_ID
Group by Dep.Name
));
Error:
Sub query returned more than 1 value.
This is not premitted when the subquery follows =, != ,< <=, >, >= or when the subquery is used as an expression
推荐答案
Select Count(*) from department Dep, Doctor do
Where Dep.De_ID = Do.De_ID
Group by Dep.Name
返回多行,因为它是一个GROUP BY查询,它应该是它应该做的!
但外部查询只需要一个值,所以你得到一个错误。
使用 []。
Returns more than one row, because it is a GROUP BY query and that is what it is supposed to do!
But the outer query expects only one value, so you get an error.
Look at using INSERT INTO SELECT Statement[^] instead.
这篇关于我想通过从医生表中获取值来在部门中插入总医生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!