|
本帖最后由 softy 于 2015-4-23 15:04 编辑
A_RNC
RNCName RncId
RNC01 2096
RNC02 2097
A_WCEL
RncId WBTSId LcrId
2096 33 1
2096 104 1
2096 104 2
2096 104 3
2097 53 1
2097 53 2
结果
RNCName RncId WBTS_COUNT WCELL_COUNT
RNC01 2096 2 4
RNC02 2097 1 2
WBTS_COUNT查询:
SELECT B.RncId, Count(B.RncId) AS WBTS_COUNT
FROM (SELECT DISTINCT A_WCEL.RncId, A_WCEL.WBTSId FROM A_WCEL) AS B
GROUP BY B.RncId;
WCELL_COUNT查询:
SELECT DISTINCT A_WCEL.RncId, Count(A_WCEL.RncId) AS WCELL_COUNT
FROM A_WCEL
GROUP BY A_WCEL.RncId;
结果:
SELECT A_RNC.RNCName, WCELL_COUNT.RncId, WBTS_COUNT.WBTS_COUNT, WCELL_COUNT.WCELL_COUNT
FROM (A_RNC LEFT JOIN WCELL_COUNT ON A_RNC.RncId = WCELL_COUNT.RncId) LEFT JOIN WBTS_COUNT ON WCELL_COUNT.RncId = WBTS_COUNT.RncId;
其实就是wbts去重后的数目,LcrId的数目
为了得到这个结果,我中间有几个过渡的查询,能否何必合并这些过渡的查询,直接得出结果呢?多谢
bts_count.rar
(18.55 KB, 下载次数: 4)
|
|