我有两张桌子:
TB_Departament
(
id_dep, nome
1 , RRHH
2 , Security
3 , logistics
)
TB_Incident
(
id_tipo, id_dep
1 , 1
2 , 3
1 , 3
2 , 1
1 , 3
2 , 1
2 , 1
)
如果我算上记录部门得到这个:
select d.nome, count(i.id_tipo) as Num from TB_Departament d, TB_Incident i
where i.id_dep = d.id_dep
group by d.nome
RESP:
RRHH 4
logistics 3
但我需要这个:
RRHH 4
Security 0
logistics 3
如何修改查询以获得正确的答案?
答案 0 :(得分:1)
尝试:
SELECT d.nome, count(i.id_tipo)
FROM TB_Departament d LEFT JOIN
TB_Incident i
ON d.id_dep = i.id_dep
GROUP BY d.nome
答案 1 :(得分:0)
在MSSQL上,这将如下所示,包括order by子句,以防你希望结果由id_dep#
发出int main(void)
{
int valid_input();
int ll_input=0;
int resp;
hash_table obj;
int bucket;
while(1)
{
ll_input=valid_input();
if(ll_input>10)
{
break;
}
obj.insert(ll_input);
}
obj.print_ll();
return 0;
}
int valid_input()
{
int input;
printf("\n\rEnter the value: ");
std::cin >> input;
while(std::cin.fail())
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
printf("\n\rBad entry!\n\rEnter the value: ");
std::cin>>input;
}
return input;
}