문제

I have a table something like this:

ID|Value
01|1
02|4
03|12
01|5
02|14
03|22
01|9
02|32
02|62
01|13
03|92

I want to know how much progress have each id made (from initial or minimal value)
so in sybase I can type:

select ID, (value-min(value)) from table group by id;

ID|Value
01|0
01|4
01|8
01|12
02|0
02|10
02|28
02|58
03|0
03|10
03|80

But monetdb does not support this (I am not sure may be cz it uses SQL'99).
Group by only gives one column or may be average of other values but not the desired result.

Are there any alternative to group by in monetdb?

도움이 되었습니까?

해결책

You can achieve this with a self join. The idea is that you build a subselect that gives you the minimum value for each id, and then join that to the original table by id.

SELECT a.id, a.value-b.min_value
FROM "table" a INNER JOIN
    (SELECT id, MIN(value) AS min_value FROM "table" GROUP BY id) AS b
    ON a.id = b.id;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top