@@ -34,17 +34,18 @@ public interface TariffInfoRepository extends JpaRepository<TariffInfo, String>
|
||||
|
||||
@Query(value = """
|
||||
SELECT
|
||||
COALESCE(t.tariff_name, 'NULL') as tariff_name,
|
||||
t.tariff_name,
|
||||
COUNT(u.id) as user_count,
|
||||
(COUNT(u.id) * 100.0) / NULLIF(
|
||||
(SELECT COUNT(*) FROM users u2
|
||||
WHERE :activeOnly = false OR u2.is_active = true
|
||||
WHERE (:activeOnly = false OR u2.is_active = true)
|
||||
AND u2.personal_tariff_info_id IS NOT NULL
|
||||
), 0
|
||||
) as usage_percent
|
||||
FROM users u
|
||||
LEFT JOIN tariff_info pti ON u.personal_tariff_info_id = pti.id
|
||||
LEFT JOIN tariff t ON pti.tariff_id = t.id
|
||||
WHERE :activeOnly = false OR u.is_active = true
|
||||
INNER JOIN tariff_info pti ON u.personal_tariff_info_id = pti.id
|
||||
INNER JOIN tariff t ON pti.tariff_id = t.id
|
||||
WHERE (:activeOnly = false OR u.is_active = true)
|
||||
GROUP BY t.id, t.tariff_name
|
||||
ORDER BY user_count DESC
|
||||
""", nativeQuery = true)
|
||||
|
||||
Reference in New Issue
Block a user