kreqq_
kreqq_

Reputation: 43

How to create a function for getting total amount?

This is my table

enter image description here

I want to create a function that get the total amoun of duration for a car/(regNr)

It should take the argument regNr and calculate the amount of duration

So for example ABC123 should get the total duration - 180.

Thanks.

Upvotes: 0

Views: 33

Answers (1)

Raptor
Raptor

Reputation: 54212

You can try this:

SELECT regNr, CONCAT('total duration - ', SUM(duration)) AS output FROM table_name
GROUP BY regNr

which will output:

regNr         output
======================================
ABC123        total duration - 180
DEF456        total duration - 130

Upvotes: 1

Related Questions