MySQL ROLLUP: Wrong total for one column calculated by a formula -
in query below, 1 of rollup sums has formula referring other columns. seems in case mysql uses formula in rollup line instead of totaling column values.
the value nertek
seems calculated using fields in total line, i.e. (462.053-479.710+0)*2700
, result -47673.9 instead of summing column values 61632-75232-12214-21744-3945+4079-43697+13500 = -77621
.
what doing wrong?
mysql> select k.nvalasztekkey nvalasztekkey, k.nerdokey nerdokey, concat(v.sfafaj, ' ', v.svnev) svalasztek, concat_ws(' ', e.sfalu, e.serdoresz, r.sname) serdoraktar, k.nhossz nhossz, elk.nm3ar, sum(fkiterm) fkiterm,sum(felad) felad, sum(fvasar) fvasar, sum(fkiterm)+sum(fvasar)-sum(felad) fkeszlet,(sum (fkiterm)+sum(fvasar)-sum(felad))*elk.nm3ar nertek keszlet k left join elokalk elk on (k.nvalasztekkey=elk.nvalasztekkey , k.nerdokey=elk.nkey) left join valasztekok v on (k.nvalasztekkey=v.nkey) left join erdok e on (k.nerdokey=e.nkey) left join raktarak r on (k.nerdokey-1000000=r.nkey) nerdokey =2 group k.nerdokey, k.nvalasztekkey, k.nhossz rollup; +---------------+----------+------------------------+-------------+--------+-------+---------+---------+--------+----------+-------------+ | nvalasztekkey | nerdokey | svalasztek | serdoraktar | nhossz | nm3ar | fkiterm | felad | fvasar | fkeszlet | nertek | +---------------+----------+------------------------+-------------+--------+-------+---------+---------+--------+----------+-------------+ | 14 | 2 | nyár hámozási rönk | laskod 57/h | 260 | 10700 | 101.480 | 95.720 | 0.000 | 5.760 | 61632.0000 | | 14 | 2 | nyár hámozási rönk | laskod 57/h | null | 10700 | 101.480 | 95.720 | 0.000 | 5.760 | 61632.0000 | | 15 | 2 | nyár belföldi rönk | laskod 57/h | 250 | 7200 | 133.123 | 143.572 | 0.000 | -10.449 | -75232.8000 | | 15 | 2 | nyár belföldi rönk | laskod 57/h | null | 7200 | 133.123 | 143.572 | 0.000 | -10.449 | -75232.8000 | | 16 | 2 | nyár kivágás | laskod 57/h | 120 | 6200 | 39.830 | 41.800 | 0.000 | -1.970 | -12214.0000 | | 16 | 2 | nyár kivágás | laskod 57/h | null | 6200 | 39.830 | 41.800 | 0.000 | -1.970 | -12214.0000 | | 18 | 2 | nyár forgácsfa | laskod 57/h | 100 | 2400 | 18.940 | 28.000 | 0.000 | -9.060 | -21744.0000 | | 18 | 2 | nyár forgácsfa | laskod 57/h | null | 2400 | 18.940 | 28.000 | 0.000 | -9.060 | -21744.0000 | | 22 | 2 | fenyö rönk | laskod 57/h | 250 | 7200 | 14.852 | 15.400 | 0.000 | -0.548 | -3945.6000 | | 22 | 2 | fenyö rönk | laskod 57/h | null | 7200 | 14.852 | 15.400 | 0.000 | -0.548 | -3945.6000 | | 24 | 2 | fenyö kivágás | laskod 57/h | 80 | 6200 | 10.758 | 10.100 | 0.000 | 0.658 | 4079.6000 | | 24 | 2 | fenyö kivágás | laskod 57/h | 120 | 6200 | 81.070 | 88.118 | 0.000 | -7.048 | -43697.6000 | | 24 | 2 | fenyö kivágás | laskod 57/h | null | 6200 | 91.828 | 98.218 | 0.000 | -6.390 | -39618.0000 | | 26 | 2 | fenyö forgácsfa | laskod 57/h | 100 | 2700 | 62.000 | 57.000 | 0.000 | 5.000 | 13500.0000 | | 26 | 2 | fenyö forgácsfa | laskod 57/h | null | 2700 | 62.000 | 57.000 | 0.000 | 5.000 | 13500.0000 | | null | 2 | fenyö forgácsfa | laskod 57/h | null | 2700 | 462.053 | 479.710 | 0.000 | -17.657 | -47673.9000 | | null | null | fenyö forgácsfa | laskod 57/h | null | 2700 | 462.053 | 479.710 | 0.000 | -17.657 | -47673.9000 | +---------------+----------+------------------------+-------------+--------+-------+---------+---------+--------+----------+-------------+
found it. correct formula field sum((fkiterm+fvasar-felad)*elk.nm3ar) nertek
.
Comments
Post a Comment