> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-fbfa8bee.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# argMinIf

> مثال على استخدام المُركِّب argMinIf

<div id="description">
  ## الوصف
</div>

يمكن تطبيق المُركِّب التجميعي [`If`](/ar/reference/functions/aggregate-functions/combinators#-if) على الدالة [`argMin`](/ar/reference/functions/aggregate-functions/argMin)
للعثور على قيمة `arg` المقابلة للقيمة الدنيا لـ `val` في الصفوف التي تكون فيها قيمة الشرط `true`،
باستخدام دالة المُركِّب التجميعي `argMinIf`.

تكون الدالة `argMinIf` مفيدة عندما تحتاج إلى العثور على القيمة المرتبطة
بالقيمة الدنيا في مجموعة بيانات، ولكن فقط في الصفوف التي تستوفي
شرطًا محددًا.

<div id="example-usage">
  ## مثال على الاستخدام
</div>

في هذا المثال، سنُنشئ جدولًا يخزّن أسعار المنتجات وطوابعها الزمنية،
وسنستخدم `argMinIf` للعثور على أقل سعر لكل منتج عند توفره في المخزون.

```sql title="Query" theme={null}
CREATE TABLE product_prices(
    product_id UInt32,
    price Decimal(10,2),
    timestamp DateTime,
    in_stock UInt8
) ENGINE = MergeTree
ORDER BY ();

INSERT INTO product_prices VALUES
    (1, 10.99, '2024-01-01 10:00:00', 1),
    (1, 9.99, '2024-01-01 10:05:00', 1),
    (1, 11.99, '2024-01-01 10:10:00', 0),
    (2, 20.99, '2024-01-01 11:00:00', 1),
    (2, 19.99, '2024-01-01 11:05:00', 1),
    (2, 21.99, '2024-01-01 11:10:00', 1);

SELECT
    product_id,
    argMinIf(price, timestamp, in_stock = 1) AS lowest_price_when_in_stock
FROM product_prices
GROUP BY product_id;
```

ستعثر الدالة `argMinIf` على السعر المقابل لأقدم طابع زمني لكل منتج،
ولكن مع احتساب الصفوف التي فيها `in_stock = 1` فقط. على سبيل المثال:

* المنتج 1: من بين الصفوف المتوفرة في المخزون، السعر 10.99 هو صاحب أقدم طابع زمني (10:00:00)
* المنتج 2: من بين الصفوف المتوفرة في المخزون، السعر 20.99 هو صاحب أقدم طابع زمني (11:00:00)

```response title="Response" theme={null}
   ┌─product_id─┬─lowest_price_when_in_stock─┐
1. │          1 │                      10.99 │
2. │          2 │                      20.99 │
   └────────────┴────────────────────────────┘
```

<div id="see-also">
  ## انظر أيضًا
</div>

* [`argMin`](/ar/reference/functions/aggregate-functions/argMin)
* [`argMax`](/ar/reference/functions/aggregate-functions/argMax)
* [`argMaxIf`](/ar/guides/clickhouse/examples/aggregate-function-combinators/argMaxIf)
* [`If مُركِّب`](/ar/reference/functions/aggregate-functions/combinators#-if)
