Как вы рассчитываете появление одной и той же категории с оконной функцией PSQL? - PullRequest
0 голосов
/ 17 марта 2019
(
SELECT
  foods.id,
  foods.category,
  ??? OVER (PARTITION BY foods.category) as same_category_order_of_occurance,
  ??? OVER (PARTITION BY foods.category) as different_category_order_of_occurance
FROM foods
) as condition ON conditions.id = foods.id
```

To product this result.

```
id | category  | same_category_order_of_occurance  | different_category_order_of_occurance
---+-----------+-----------------------------------+---------------------------------------
1  |FRUIT      | 1                                 | 1                  
2  |FRUIT      | 2                                 | 1
3  |VEG        | 1                                 | 2
4  |VEG        | 2                                 | 2
5  |MEAT       | 1                                 | 3
6  |MEAT       | 2                                 | 3
```

Uncertain what functions to use which help me produce this ordering.
...