我需要一些关于计算数据的帮助。
到目前为止,这是我的查询:
SELECT COUNT(*) FROM (SELECT COUNT(biodata.Nomor_Induk) as jumData
FROM biodata
INNER JOIN statuspegawai ON biodata.Nomor_Induk = statuspegawai.Nomor_Induk
WHERE statuspegawai.bagian='IT'
GROUP BY biodata.Nomor_Induk)
我有两张桌子:biodata
和statuspegawai
。
两个表都有Nomor_Induk
列。
答案 0 :(得分:1)
您的查询需要子查询表别名:
select count(*)
FROM (SELECT COUNT(biodata.Nomor_Induk) as jumData
from biodata INNER JOIN
statuspegawai
ON biodata.Nomor_Induk = statuspegawai.Nomor_Induk
where statuspegawai.bagian = 'IT'
Group By biodata.Nomor_Induk
) t;
您也可以在没有子查询的情况下表达这一点:
select COUNT(distinct biodata.Nomor_Induk) as jumData
from biodata INNER JOIN
statuspegawai
ON biodata.Nomor_Induk = statuspegawai.Nomor_Induk
where statuspegawai.bagian = 'IT';
答案 1 :(得分:1)
请在此处使用以下代码:
-missing table别名!
select count(*) FROM (
SELECT COUNT(biodata.Nomor_Induk) as jumData
from biodata INNER JOIN
statuspegawai
ON biodata.Nomor_Induk = statuspegawai.Nomor_Induk
where statuspegawai.bagian='IT'
Group By biodata.Nomor_Induk
) as Alias1;