# Ops

## Detect duplicate orders

This will return the orders coming from the same and to collective and same amount within the same minute

```
with res as (
  SELECT 
    substring(cast(DATE_TRUNC('minute', o."createdAt") as text) from 1 for 16) as minute,
    count(*) as count, "FromCollectiveId", "CollectiveId", "totalAmount", max(o."currency") as currency,
    o.description,
    MAX(s."isActive"::INT) as "activeSubscription"
  FROM "Orders" o
  LEFT JOIN "Subscriptions" s ON o."SubscriptionId"=s.id
  WHERE (s."isActive" IS TRUE OR s.id IS NULL) AND o."deletedAt" IS NULL AND o."processedAt" IS NOT NULL AND o."PaymentMethodId" IS NOT NULL
  GROUP BY "FromCollectiveId", "CollectiveId", "totalAmount", "minute", o."description"
  ORDER BY count DESC
)
SELECT fc.slug, fc.type, r.*
FROM res r
LEFT JOIN "Collectives" fc ON fc.id=r."FromCollectiveId"
WHERE count > 1 ORDER BY r.count DESC
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentarians.gitbook.io/metadocumentation/internal/queries/ops.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
