I am trying to retrieve records based on a custom field "ci_ku". For the same values of "ci_ku" we will be having multiple "l1m_visits", and I want to retrieve the minimum value of "l1mvisits" for each "ci_ku".
Sample Data:
| ku | ci_ku | l1m_visits |
|---|---|---|
| 1234-5678-HIJK | 1234-HIJK | A |
| 1234-9012-HIJK | 1234-HIJK | B |
Expected Output:
| ku | ci_ku | l1m_visits |
|---|---|---|
| 1234-5678-HIJK | 1234-HIJK | A |
Have tried the query below:
SELECT DISTINCT REGEXP_REPLACE(ku, CONCAT('-',CAST(v_nbr AS varchar)), '') AS ci_ku,
ku,
MIN(l1m_visits),
last_refresh_date
FROM db.schema.table
GROUP BY ci_ku;
and facing the following error:
line 1:194: Column 'ci_ku' cannot be resolved