add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
userID dt
1 2030-01-01
2 2030-02-01
3 2030-01-02
1 2030-01-02
1 2030-04-01
concat(
  'select userID, ',
  group_concat(distinct "sum(dt='", dt, "') as '", dt, "'" order by dt),
  ' from sample group by userID'
)
select userID, sum(dt='2030-01-01') as '2030-01-01',sum(dt='2030-01-02') as '2030-01-02',sum(dt='2030-02-01') as '2030-02-01',sum(dt='2030-04-01') as '2030-04-01' from sample group by userID
@stmt
select userID, sum(dt='2030-01-01') as '2030-01-01',sum(dt='2030-01-02') as '2030-01-02',sum(dt='2030-02-01') as '2030-02-01',sum(dt='2030-04-01') as '2030-04-01' from sample group by userID
userID 2030-01-01 2030-01-02 2030-02-01 2030-04-01
1 1 1 0 1
2 0 0 1 0
3 0 1 0 0