Good day to all! Faced such a problem, there is a request that returns
| SOT | KUT | K1 | K2 | YADRO | GR | |------|------|----|----|-------|-----| | 2055 | 1,31 | 0 | 3 | 2 | 101 | | 2055 | 1,31 | 0 | 3 | 2 | 101 | | 2055 | 1,31 | 0 | 3 | 2 | 103 | | 2055 | 1,31 | 1 | 0 | 1 | 100 | | 2055 | 1,31 | 0 | 3 | 3 | 102 | | 2055 | 1,31 | 0 | 3 | 3 | 102 | Where columns K1 and K2 are calculated, K1 shows how many different groups (GR) belong to the core (YADRO) 1 employee visits (SOT), K2 shows how many different groups (GR) does not belong to the core (YADRO) 1 visits employee (SOT). Kernels contain only unique groups; groups do not repeat in two different kernels. Request
select sot, round(sum(time)over(partition by sot)/25920,2) as Кутил, case when yadro=2 then count(distinct gr)over(partition by sot,case when yadro=2 then 0 else 1 end) else 0 end as K1, case when yadro!=2 then count(distinct gr)over(partition by sot,case when yadro!=2 then 0 else 1 end) else 0 end as K2, ... from ... The problem is that the query returns values with zeros and it is necessary that it be something like this
| SOT | KUT | K1 | K2 | YADRO | GR | |------ |------ |---- |---- |------- |----- | | 2055 | 1,31 | 1 | 3 | 2 | 101 | | 2055 | 1,31 | 1 | 3 | 2 | 101 | | 2055 | 1,31 | 1 | 3 | 2 | 103 | | 2055 | 1,31 | 1 | 3 | 1 | 100 | | 2055 | 1,31 | 1 | 3 | 3 | 102 | | 2055 | 1,31 | 1 | 3 | 3 | 102 | So that there are no zeros but there are common numbers in all columns, I will be very grateful for the help, I immediately say that wrappers should be offered only as a last resort, I would like to do without unnecessary subqueries, etc.
case when yadro=2 thenit returns 0 whereyadro<>2- Batanichek