mysql - Inserting values based on the values from another table -


i'm afraid 'case when' statements not working below , i'm wondering if there's different way i'm trying do. in table cdrdb.session a have field called legtype1 , in cdrdb.callsummary b have field called answered.

in test.ambrawdatadump, i'm trying insert columns based on each phone call previous tables. basically, if legtype1 = 2 , answered = 1 that's inbound answered call. if legtype1 = 2 , answered = 0 that's missed call, , finally, if legtype1 = 1 that's outbound call.

ideally every record in table, after insert, should have 1 in 1 of columns , 0 in other 2 columns. i'm seeing lot of records have 1 in missed , outbound column, incorrect. there more explicit way me using case when?

insert test.ambrawdatadump(             extension,              start_time,             end_time,             duration,              inbound_answered,              missed,              outbound,              hold_time,             phone_number,             phone_number2,             call_term_reason)   select                c.extension -- user extension             , b.starttime -- start of call             , b.endtime   -- end of call             , b.duration  -- length of call             , case when a.legtype1 = 2 , answered = 1                1 else 0 end inbound_answered     -- inbound answered calls             , case when a.legtype1 = 2 , answered = 0               1 else 0 end missed               -- missed calls             , case when a.legtype1 = 1               1 else 0 end outbound               -- outbound calls             , a.holdtimesecs -- hold time in seconds             , a.callingpartyno             , a.finallycalledpartyno             , a. terminationreasoncode cdrdb.session inner join cdrdb.callsummary b  on a.notablecallid = b.notablecallid; 


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -