Telegram Group & Telegram Channel
🧠 SQL-задача с подвохом: "Невидимые дубликаты"

В таблице users хранятся email-адреса пользователей. Некоторые юзеры регистрируются повторно, маскируя один и тот же email по-разному:

| id | name | email |
|----|----------|--------------------------|
| 1 | Alice | [email protected] |
| 2 | Bob | [email protected] |
| 3 | Charlie | [email protected] |
| 4 | Dave | [email protected] |
| 5 | Eve | [email protected] |


🎯 Цель:
Найти количество уникальных пользователей, если:
- Регистр не учитывается (`alice` = `ALICE`)
- Пробелы игнорируются
- Для @gmail.com:
— Убираются точки в имени
— Всё после + отрезается

SQL-решение:


SELECT COUNT(DISTINCT normalized_email) AS unique_users
FROM (
SELECT
CASE
WHEN email ILIKE '%@gmail.com' THEN
REGEXP_REPLACE(
SPLIT_PART(SPLIT_PART(LOWER(TRIM(email)), '+', 1), '@', 1),
'\.', '', 'g'
) || '@gmail.com'
ELSE
LOWER(REPLACE(TRIM(email), ' ', ''))
END AS normalized_email
FROM users
) AS cleaned;


🔍 Как это работает:

LOWER(TRIM(email)) — убираем пробелы и регистр

SPLIT_PART(..., '+', 1) — отрезаем всё после +

REGEXP_REPLACE(..., '\.', '', 'g') — удаляем точки

Считаем DISTINCT, чтобы получить число уникальных email'ов

🔥 Используй такие трюки для:
• антифрода
• чистки базы
• аналитики поведения пользователей

#SQL #PostgreSQL #Gmail #EmailNormalization #DevTools #AntiFraud #DataCleaning #Analytics



tg-me.com/sqlhub/1904
Create:
Last Update:

🧠 SQL-задача с подвохом: "Невидимые дубликаты"

В таблице users хранятся email-адреса пользователей. Некоторые юзеры регистрируются повторно, маскируя один и тот же email по-разному:

| id | name | email |
|----|----------|--------------------------|
| 1 | Alice | [email protected] |
| 2 | Bob | [email protected] |
| 3 | Charlie | [email protected] |
| 4 | Dave | [email protected] |
| 5 | Eve | [email protected] |


🎯 Цель:
Найти количество уникальных пользователей, если:
- Регистр не учитывается (`alice` = `ALICE`)
- Пробелы игнорируются
- Для @gmail.com:
— Убираются точки в имени
— Всё после + отрезается

SQL-решение:


SELECT COUNT(DISTINCT normalized_email) AS unique_users
FROM (
SELECT
CASE
WHEN email ILIKE '%@gmail.com' THEN
REGEXP_REPLACE(
SPLIT_PART(SPLIT_PART(LOWER(TRIM(email)), '+', 1), '@', 1),
'\.', '', 'g'
) || '@gmail.com'
ELSE
LOWER(REPLACE(TRIM(email), ' ', ''))
END AS normalized_email
FROM users
) AS cleaned;


🔍 Как это работает:

LOWER(TRIM(email)) — убираем пробелы и регистр

SPLIT_PART(..., '+', 1) — отрезаем всё после +

REGEXP_REPLACE(..., '\.', '', 'g') — удаляем точки

Считаем DISTINCT, чтобы получить число уникальных email'ов

🔥 Используй такие трюки для:
• антифрода
• чистки базы
• аналитики поведения пользователей

#SQL #PostgreSQL #Gmail #EmailNormalization #DevTools #AntiFraud #DataCleaning #Analytics

BY Data Science. SQL hub


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/sqlhub/1904

View MORE
Open in Telegram


Data Science SQL hub Telegram | DID YOU KNOW?

Date: |

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.

Data Science SQL hub from kr


Telegram Data Science. SQL hub
FROM USA