# \[es 5.6.8\] How to tanslate this postgre sql to es ver -- order by count(id) over (partition by org\_name, visit\_datetime) desc

**URL:** <https://discuss.elastic.co/t/es-5-6-8-how-to-tanslate-this-postgre-sql-to-es-ver-order-by-count-id-over-partition-by-org-name-visit-datetime-desc/343042>\
**Category:** Elasticsearch\
**Created:** [September 14, 2023, 10:25am UTC](https://discuss.elastic.co/t/es-5-6-8-how-to-tanslate-this-postgre-sql-to-es-ver-order-by-count-id-over-partition-by-org-name-visit-datetime-desc/343042 "2023-09-14T10:25:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vvneedspeed](https://avatars.discourse-cdn.com/v4/letter/v/e9c0ed/32.png) [@vvneedspeed](https://discuss.elastic.co/u/vvneedspeed)\
**Post date:** [September 14, 2023, 10:25am UTC](https://discuss.elastic.co/t/es-5-6-8-how-to-tanslate-this-postgre-sql-to-es-ver-order-by-count-id-over-partition-by-org-name-visit-datetime-desc/343042/1 "2023-09-14T10:25:57Z")

</div>

Hi there, I'm stuck. How to tanslate this postgre sql to Elasticsearch ver?  
The Elasticsearch is 5.6.8, but the solution with higher version is also welcome!

```sql
select user_name from tablea  
order by count(meid) over (partition by org_name, visit_datetime) desc
limit 10
offset 10

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 12, 2023, 10:26am UTC](https://discuss.elastic.co/t/es-5-6-8-how-to-tanslate-this-postgre-sql-to-es-ver-order-by-count-id-over-partition-by-org-name-visit-datetime-desc/343042/2 "2023-10-12T10:26:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
