mysql UNION wrong result? -


i have query this

(select s1.m m,ifnull(s2.y,2013) y,ifnull(s2.s,0) planned (select 1 m  union select 2  union select 3  union select 4  union select 5  union select 6  union select 7  union select 8  union select 9  union select 10  union select 11    union select 12) s1 left join (select year(p.pdate2) y,month(p.pdate2) m, sum(p.totwdisc) s   pro_partial_inv p year(p.pdate2)=2013 group y,m) s2 on s1.m=s2.m) union (select s5.m m,ifnull(s3.y,2013) y,ifnull(s3.s,0) realv (select 1 m  union select 2  union select 3  union select 4  union select 5  union select 6  union select 7  union select 8  union select 9  union select 10  union select 11    union select 12) s5 left join (select year(p.paidd) y,month(p.paidd) m, sum(p.totwdisc) s  pro_partial_inv p p.status=2 , year(p.paidd)=2013 group y,m) s3 on s5.m=s3.m) union (select s6.m m,ifnull(s4.y,2013) y,ifnull(s4.s,0) proj (select 1 m  union select 2  union select 3  union select 4  union select 5  union select 6  union select 7  union select 8  union select 9  union select 10  union select 11    union select 12) s6 left join (select year(p.startd) y,month(p.startd) m, sum(p.disc_n) s pro_project  p year(p.startd)=2013 group y,m) s4 on s6.m=s4.m) 

so need this:

m       y     planned  1   2013    0.00     2   2013    0.00     3   2013    0.00     4   2013    0.00     5   2013    0.00     6   2013    908.18     7   2013    0.00     8   2013    1136.36     9   2013    13354.54     10  2013    0.00     11  2013    0.00     12  2013    0.00     1   2013    0.00     2   2013    0.00     3   2013    0.00     4   2013    0.00     5   2013    0.00     6   2013    908.18     7   2013    0.00     8   2013    1136.36     9   2013    13354.54     10  2013    0.00     11  2013    0.00     12  2013    0.00 1   2013    0.00     2   2013    0.00     3   2013    0.00     4   2013    0.00     5   2013    0.00     6   2013    908.18     7   2013    0.00     8   2013    1136.36     9   2013    13354.54     10  2013    0.00     11  2013    0.00     12  2013    0.00 

it 3 unions similar different. m represents month, y year , planned values calculation. result this:

m       y     planned  1   2013    0.00     2   2013    0.00     3   2013    0.00     4   2013    0.00     5   2013    0.00     6   2013    908.18     7   2013    0.00     8   2013    1136.36     9   2013    13354.54     10  2013    0.00     11  2013    0.00     12  2013    0.00 6   2013    0.00 7   2013    809.09 8   2013    2227.27 9   2013    0.00 7   2013    43600.00 8   2013    41330.00 

am doing wrong? not sure why here not made union 3 times, when run queries separated result.

i suspect 2 unions need changed union all between 3 "major" queries. prevents duplicates being removed.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -