-1

I'm trying to make a query which would look like this..

|tipe of operation | UMT | Total |
__________________________________
|reach             | 1.5 |  1.5  | 
|reach             | 1.5 |  3    | 
|reach             | 1.5 |  4.5  | 
|take              | 1   |  5.5  | 
|take              | 2   |  7.5  |

(that the total field is added together according to the columns)*

I have tried in several ways and I can not achieve ..... so far my most advanced query is this, which gives me the following result ...

|tipe of operation | UMT | Total |
__________________________________
|reach             | 1.5 |  1.5  | 
|reach             | 1.5 |  1.5  | 
|reach             | 1.5 |  1.5  | 
|take              | 1   |  1    | 
|take              | 1   |  1    |

this is my query

select   tablamtmtipo as 'tipe of operation'
       , tablamtmdatos as 'UMT'
       , sum(tablamtmdatos) as Total 
from tablamtm 
WHERE tablamtmoperacion = 'operación 1' 
group by idtablamtm

I only have one table with these fields

1- idtablamtm
2- tablamtmoperacion
3- tablamtmtype
4- tablamtmdatos
Tolu
  • 175
  • 4
  • 10
Jorge1023
  • 21
  • 4

1 Answers1

1

use this

select   tablamtmtipo as 'tipe of operation'
       , tablamtmdatos as 'UMT'
       , @total:=@total+ tablamtmdatos as Total 
from tablamtm 
WHERE tablamtmoperacion = 'operación 1' 
group by idtablamtm
Youngz ie
  • 659
  • 2
  • 7
  • 17