SELECT 
          
         LPAD( StartTime, 20, ' ' ) as 'Debut',
         LPAD( DID, 15, ' ' ) as 'SDA',
         LPAD( Name, 15, ' ' ) as 'Nom',
         LPAD( Remote, 15, ' ' ) as 'Distant',
         LPAD( Duration, 10, ' ' ) as 'Duree',
         LPAD( Code, 5, ' ' ) as 'Resultat'
 FROM (
           select 

           from_unixtime(StartTime) as StartTime, 
           di.DID,
           Name,
           if( inbound & 1 = 1,Source, Destination ) as Remote,
           SEC_TO_TIME(duration) as Duration,
           concat( if( inbound & 2 = 2, 'S', 'E' ),  if( inbound & 4 = 4, 'M','R') ) as Code 
           from VoIPNumber vn 
           JOIN Zone_nodes zn on zn.nodes = vn.id and zn.id = 479939  
           JOIN WebCDR w on w.node = vn.id 
           JOIN DIDInventory di on di.id = vn.DID 
) nn;
