sql >> Database >  >> RDS >> Mysql

Nieuwe kolom toevoegen aan resultaat en tabel samenvoegen

Ik denk dat je union all nodig hebt :

select id, campaign, event_type, 'delivered' as sub_event_type, date_delivered
from logistics
where event_type = 'stored' and date_delivered is not null
union all
select id, campaign, event_type, 'recorded' as sub_event_type, date_recorded
from logistics
where event_type = 'stored' and date_recorded is not null
union all
select id, campaign, event_type, 'completed' as sub_event_type, date_completed
from logistics
where event_type = 'stored' and date_completed is not null
union all
select id, campaign, event_type, null as sub_event_type, date_offered
from logistics
where event_type = 'offered' 
union all
select id, campaign, event_type, null as sub_event_type, date_ordered
from logistics
where event_type = 'ordered' ;



  1. Wanneer autovacuüm niet stofzuigt

  2. Xampp:webbrowser geeft de localhost-pagina niet weer

  3. Implementeer MySQL-gebeurtenismelding terug naar een Delphi-toepassing

  4. MYSQL - tel het aantal rijen in elke tabel