-1

对不起大家...

我是新手,左加入计数有问题

结构表A:

结构表 B:

----------------------
|Branch_code   | NIK
----------------------
'IDJB001BEC', '1300001'
'IDJB001BEC', '1300002'
'IDPA001PPA', '1300003'
'IDJK001MAG', '1300004'
'IDJB001BEC', '1300005'
'IDJB001BEC', ''
'IDBTNCTR', ''

结构表 C:

|branch_code|
'IDBE001BGK'
'IDBE002BGK'
'IDBTNCTR'
'IDJB001BEC'
'IDJK001HO'
'IDJK001MAG'
'IDJK001MPI'
'IDJK002MCL'
'IDJK002MPB'
'IDJK003KDY'

我希望从这样的结果中获得样本:

|Branch_code|count|
'IDJK001MAG'  0
'IDJK001MPI'  0
'IDJK002MCL'  3
'IDJK002MPB'  5
'IDJK003KDY'  4

注意:尽管该行为空/零,但“计数”字段仍显示零。

感谢师父

4

3 回答 3

0

试试这个:

SELECT c.branch_code, COUNT(b.nik) 
FROM tablec c 
LEFT JOIN tableb b ON c.branch_code, b.branch_code 
GROUP BY c.branch_code
于 2013-11-14T04:59:44.513 回答
0
select a.branch_code,count(a.nik) as nik_count from table a left join table b
on a.branch_code=b.branch_code

group by a.branch_code
于 2013-11-14T05:02:10.170 回答
0

由于您没有发布查询,因此看不到您做错了什么,但这应该可以满足您的需求:

SELECT 
c.branch_code, 
COUNT(b.nik) 
FROM tablec c 
LEFT JOIN tableb b ON c.branch_code = b.branch_code 
GROUP BY c.branch_code

SQL小提琴

于 2013-11-14T05:02:30.890 回答