各位帮忙看看,这个SQL应该怎么写
表A
cid number
content varchar2(20)
1,测试内容1
2,测试内容2
3,测试内容3
4,测试内容4
5,测试内容5
6,测试内容6
表b
cid number
flag varchar2(20)
1,1000
2,2000
3,1000
5,1000
需要查询结果如下
1000,3
2000,1
null,2
------解决方案--------------------
select b.flag, count(*) from
(select '1' cid, '1000' flag from dual
union
select '2', '2000' from dual
union
select '3', '1000' from dual
union
select '5', '1000' from dual
) b,
(
select '1' cid from dual
union
select '2' cid from dual
union
select '3' cid from dual
union
select '4' cid from dual
union
select '5' cid from dual
union
select '6' cid from dual
) a
where a.cid = b.cid(+) group by b.flag