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

CodePudding user response:

refer to the second floor wildwolv response:
you try to write like this:
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

Not tried, not sys_guid (),

CodePudding user response:

reference QQ826688096 reply: 3/f
Quote: refer to the second floor wildwolv 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

Not tried, not sys_guid (),
using yxdm group

CodePudding user response:

reference 4 floor wildwolv response:
Quote: reference QQ826688096 reply: 3/f

Quote: refer to the second floor wildwolv 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

Not tried, not sys_guid (),
using yxdm group

The above is used to group yxdm ah, not make, unless in left the join group is right

CodePudding user response:

reference 5 floor QQ826688096 reply:
Quote: refer to 4th floor wildwolv response:
Quote: reference QQ826688096 reply: 3/f

Quote: refer to the second floor wildwolv 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
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related