Нужна помощь со скриптом Python для создания агрегированных столбцов с условиями.
select
report_id,
min(date) first_activity,
max(date) last_activity,
DATEDIFF(SECOND, min(timestamp), max(timestamp))/86400.0 all_activity_diff_days,
count(distinct access_id) unique_sessions,
count(distinct report_type) unique_type,
count(CASE WHEN report_rank = 1 then report_type else null end) all_type,
count(CASE WHEN report_rank = 1 AND code <> 'xxxx' THEN report_type ELSE null END) all_type_nomerge,
SUM(CASE WHEN report_rank = 1 AND code <> 'xxxx' THEN step_count ELSE 0 END) AS All_step_count,
sum(CASE WHEN report_rank = 1 AND code <> 'xxxx' and report_type = 'HR' THEN access_time/1000 ELSE 0 END) access_time
from table_report
group by report_id