Answer the question
In order to leave comments, you need to log in
What can be added to the query to get the result?
actually here is the query
SELECT bonus, nlevel(tree) - nlevel('2.383') AS level
FROM "user"
INNER JOIN "bonus_item"
ON user_from = "user".id
AND user_to = 383
WHERE (tree ~ '2.383.*{0,5}')
AND ("mounth" = '9:2017')
order by nl;
bonus | level
--------+----
331.00 | 0
10.40 | 1
10.20 | 1
3.20 | 1
10.40 | 1
6.20 | 2
2.60 | 3
14.76 | 4
2.82 | 4
3.16 | 5
bonus | level
--------+----
331.00 | 0
34.20 | 1
6.20 | 2
2.60 | 3
17.58 | 4
3.16 | 5
Answer the question
In order to leave comments, you need to log in
Typically, in such cases, grouping is added to the query and aggregate functions are used. Try like this:
SELECT SUM(bonus), nlevel(tree) - nlevel('2.383') AS level
FROM "user"
INNER JOIN "bonus_item"
ON user_from = "user".id
AND user_to = 383
WHERE (tree ~ '2.383.*{0,5}')
AND ("mounth" = '9:2017')
GROUP BY (nlevel(tree) - nlevel('2.383'))
order by nl;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question