OriginChainDB
Sql

Find values within a range

← SQL examples

The language tabs use earlier client interfaces. Check SDK versions and connection setup before running them.

Find orders whose amount is between two limits. This example stores prices as integer cents.

Before you run it: Use > and < when the endpoints must be excluded.

Keep orders inside an inclusive price rangeBoth bounds use cents, matching the stored amount_cents column.
  1. Read order amountsUse the integer amounts in the sample table.
  2. Apply 1000 through 10000BETWEEN includes both endpoint values.
  3. Inspect matching ordersRows below or above the range are excluded.

Follow the example

  1. Load the orders from the linked setup.
  2. Set the lower and upper amounts.
  3. Run the query.
  4. Check values at both boundaries.

Run the request

First register and load the orders sample: shop.orders has id, customer_id, amount_cents and status. Use its three sample rows for the results shown here.

curl -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/sql" \
  -H "Authorization: Bearer $OC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "sql": "SELECT id, amount_cents FROM shop.orders WHERE amount_cents BETWEEN 1000 AND 10000 LIMIT 50"
  }'

Check the result

BETWEEN includes both endpoints: 1000 and 10000 match.

{
  "kind": "select",
  "rows": [
    { "id": "o_001", "amount_cents":  4990 },
    { "id": "o_003", "amount_cents":  1250 }
  ]
}

Important limits and checks

  • Off-by-one. BETWEEN is inclusive on both ends. If you mean exclusive, use col > low AND col < high.
  • Keep the units consistent. This table uses integer cents, so 1000 means 10.00 in the chosen currency. Exact decimal fields are another option; avoid binary floating-point values when exact monetary comparisons matter.

Continue

Continue to summarize rows by status.

© 2026 Silicoyn Technologies Pvt Ltd

On this page