Hi All,
I have two SQL tables: Table1 and Table2
Please, see below:
table 1 table2
userid month year parts quant list misc others userid month year parts quant list misc others
P5 3 2012 8123 10230 32 183 1200 P5 3 2012 361 102 75 42 0
p6 3 2012 92 132 7 0 75 P6 3 2012 14 2 27 11 0
P7 3 2012 5 123 45 788 0
P8 3 2012 24 18 6 425 0
P9 3 2012 8 74 15 133 0
P10 3 2012 159 456 25 32 100
p11 3 2012 7330 13342 152 138 12350
p18 3 2012 12 42 152 138 1000 P18 3 2012 5 3 8 12 0
P21 3 2012 2041 3835 273 47 198 P21 3 2012 10 20 4 5 0
p23 3 2012 37 12 8 0 27 P23 3 2012 4 7 17 18 0
p24 3 2012 22 47 7 0 0 P24 3 2012 12 6 11 0 0
I am trying to create the final data report into the table 3 from both tables (Table1 and Table2) with SQL Query statement:
SELECT userid, parts, quant, list, misc, others, (parts + quant + list + misc + others) From table1 union all SELECT userid, parts, quant, list, misc, others, (parts + quant + list + misc + others) FROM table2 as TotalResutlsTable3 WHERE month = 3 and year = 2012 and userid like 'P%' order by userid ASC
I am not sure if this SQ query is correct for calculating both table1 and table2 to final data report table3.
Like this final table 3:
Userid month year parts quant list misc others
P5 3 2012 8484 10332 108 225 1200
p6 3 2012 106 134 34 11 75
P7 3 2012 5 123 45 788 0
P8 3 2012 24 18 6 425 0
P9 3 2012 8 74 15 133 0
P10 3 2012 159 456 25 32 100
p11 3 2012 7330 13342 152 138 12350
p18 3 2012 17 45 160 150 1000
P21 3 2012 2051 3855 277 52 198
p23 3 2012 41 19 25 18 27
P24 3 2012 34 52 18 0 0
I am not sure if this SQ query is correct for calculating both table1 and table2 to final data report table3.
Your help is greatly appreciated. Thanks.