Home > database > Who often write business colleagues SQL, you can solve this result data repeated question is why?
Who often write business colleagues SQL, you can solve this result data repeated question is why?
Time:09-18
Select Sys_guid (), The count (jsb1 ZGH) nanrs, The count (jsb2 ZGH) NVRS, Count (jsb3. ZGH) nan_nv_rs, T.y Lin XMC The from dm_yxb t Left the join (select ZGH, xb, xydm from sz_jsxxb where xb='1' and xydm is not null) jsb1 on t.y Lin XDM=jsb1. Xydm Left the join (select ZGH, xb, xydm from sz_jsxxb where xb='2' and xydm is not null) jsb2 on t.y Lin XDM=jsb2. Xydm Left the join (select ZGH, xb, xydm from sz_jsxxb where xb! And xb='1'!='2' and xydm is not null) jsb3 on t.y Lin XDM=jsb3. Xydm Group by t.y Lin XMC
Above are written by the subquery optimization results, the effect can also be, from 31 seconds to 1.09 seconds, make me happy, kuang kuang's excited after a meal, is found that there is a problem, is the results of a query is bad, there are serious data error, not an error below:
The query result is as shown in the table above, "NANRS", "NVRS" content is the same, this kind of problem, looking at is not an error, in fact, the biggest problems,
I just want to know why the key column value is to be repeated?
CodePudding user response:
The right answers can be like that, this is my final application result, but I just don't know the above writing, why can lead to data repeat! Select Sys_guid (), X.r s nanrs, Y.r s NVRS, Z.r s nan_nv_rs, T.y Lin XMC The from dm_yxb t Left the join (select count (ZGH) rs, xydm from sz_jsxxb where xb='1' and xydm is not null group by xydm) x on t.y Lin XDM=7.0.x.x ydm Left the join (select count (ZGH) rs, xydm from sz_jsxxb where xb='2' and xydm is not null group by xydm) on y t.y Lin XDM=y.x ydm Left the join (select count (ZGH) rs, xydm from sz_jsxxb where xb! And xb='1'!='2' and xydm is not null group by xydm) z on t.y Lin XDM=z.x ydm
CodePudding user response:
You write so try: Select The count (jsb1 ZGH) nanrs, The count (jsb2 ZGH) NVRS, Count (jsb3. ZGH) nan_nv_rs, T.y Lin XDM The from dm_yxb t Left the join (select ZGH, xb, xydm from sz_jsxxb where xb='1' and xydm is not null) jsb1 on t.y Lin XDM=jsb1. Xydm Left the join (select ZGH, xb, xydm from sz_jsxxb where xb='2' and xydm is not null) jsb2 on t.y Lin XDM=jsb2. Xydm Left the join (select ZGH, xb, xydm from sz_jsxxb where xb! And xb='1'!='2' and xydm is not null) jsb3 on t.y Lin XDM=jsb3. Xydm Group by t.y Lin XDM