-- mysql 8.x 버전인 경우 select distinct user_id, first_value(phone_num) over (partition by user_id order by phone_num is null, date_time desc) phone_num, first_value(address) over (partition by user_id order by address is null, date_time desc) address, first_value(birth_date) over (partition by user_id order by birth_date is null, date_time desc) birth_date from data_table;
--조인 SELECT t1.user_id, t1.phone_num, t1.address, t1.birth_date FROM table t1 INNER JOIN ( SELECT user_id, MAX(date_time) AS max_date_time FROM table GROUP BY user_id ) t2 ON t1.user_id = t2.user_id AND t1.date_time = t2.max_date_time --분석함수 SELECT user_id, phone_num, address, birth_date FROM ( SELECT user_id, phone_num, address, birth_date, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY date_time DESC) AS row_num FROM table ) AS t1 WHERE row_num = 1;