innovationacademy-kr / 42seoul-info

42 Cadet 정보를 확인할 수 있는 프로젝트
8 stars 3 forks source link

[REFACTOR] 기수 필드 추가 #17

Open kenu opened 3 years ago

kenu commented 3 years ago

group

kenu commented 3 years ago
/* final batch */

update users as t1 join (
  select id,
  case
    when begin_at between '2020-01' and '2020-05' then 1
    when begin_at in ('2020-06', '2020-07') then 2
    when begin_at in ('2020-10', '2020-11', '2021-01') then 3
    else 4
  end as `grouped`
  from (
    select
      id, username, substr(str_to_date(json_extract(data, '$.cursus_users[0].begin_at'),'"%Y-%m-%dT%T.%fZ"'), 1, 7) begin_at
    from users
    where str_to_date(json_extract(data, '$.cursus_users[1].begin_at'),'"%Y-%m-%dT%T.%fZ"') is not null
  ) aa
) as t2
using (id)
set t1.`group` = t2.`grouped`
where t1.`group` is null
;

select `group`, count(*) 
from users
group by `group`
;