> ## 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.

# countIf

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

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

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

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

في هذا المثال، سننشئ جدولًا لتخزين محاولات تسجيل دخول المستخدمين،
وسنستخدم `countIf` لحساب عدد عمليات تسجيل الدخول الناجحة.

```sql title="Query" theme={null}
CREATE TABLE login_attempts(
    user_id UInt32,
    timestamp DateTime,
    is_successful UInt8
) ENGINE = MergeTree
ORDER BY ();

INSERT INTO login_attempts VALUES
    (1, '2024-01-01 10:00:00', 1),
    (1, '2024-01-01 10:05:00', 0),
    (1, '2024-01-01 10:10:00', 1),
    (2, '2024-01-01 11:00:00', 1),
    (2, '2024-01-01 11:05:00', 1),
    (2, '2024-01-01 11:10:00', 0);

SELECT
    user_id,
    countIf(is_successful = 1) AS successful_logins
FROM login_attempts
GROUP BY user_id;
```

تحسب الدالة `countIf` فقط الصفوف التي تكون فيها `is_successful = 1` لكل مستخدم.

```response title="Response" theme={null}
   ┌─user_id─┬─successful_logins─┐
1. │       1 │                 2 │
2. │       2 │                 2 │
   └─────────┴───────────────────┘
```

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

* [`count`](/ar/reference/functions/aggregate-functions/count)
* [`If مُركِّب`](/ar/reference/functions/aggregate-functions/combinators#-if)
