sql >> データベース >  >> RDS >> Mysql

結果と合体テーブルに新しい列を追加します

    union allが必要だと思います :

    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. インポートエクスポートmysqlデータベースコマンドライン超高速

    2. INSERT COMMAND ::エラー:列の値が存在しません

    3. OracleのREGEXP_INSTR()関数

    4. 異なるデータベース間で外部キー制約を維持する方法は?