The query which works looks like this :
SELECT d.dosno,
CAST(SUM(k.uur) + SUM(k.minuut) / 60 AS VARCHAR(4)) + 'u ' +
CAST(SUM(k.minuut) % 60 AS VARCHAR (2)) + 'm' AS derivedColumn
FROM dbo.kbpres AS k INNER JOIN
dbo.doss AS d ON k.ino = d.ino
WHERE (d.dosno = '93690')
GROUP BY d.dosno
I would like to add this :
(SUM(k.uur) * 60 + SUM(k.minuut)) * k.prijs AS TotalCost
but then I should add k.prijs to the groupby according to the error I get, but I don’t want this because then I get 21 results instead of just one totalresult.
example :
dosno uur minuut prijs
93690 0 5 2
93690 1 0 1
93690 0 10 2
93690 0 5 5
result I need is :
93690 1:20 800
The answer is to add:
– to your query – this will derive the cost for each row and then sum those costs.
EDIT: to sum prijs only where soort is K, add:
– to the existing query.