Monday 16 June 2014

Finding missing sequence in mysql server

select t1.eventlogid + 1 as missing_id
from ka_eventlognew1 t1
left join ka_eventlognew1 t2 on t2.eventlogid = t1.eventlogid + 1
where t2.eventlogid is null;

select t1.eventlogid - 1 as missing_id
from ka_eventlognew1 t1
left join ka_eventlognew1 t2 on t2.eventlogid = t1.eventlogid - 1
where t2.eventlogid is null;

split fn mn and ln

SELECT
   SUBSTRING_INDEX(SUBSTRING_INDEX(displaypart, ' ', 1), ' ', -1) AS first_name,
   If(  length(displaypart) - length(replace(displaypart, ' ', ''))>1,
       SUBSTRING_INDEX(SUBSTRING_INDEX(displaypart, ' ', 2), ' ', -1) ,'')
           as middle_name,
   SUBSTRING_INDEX(SUBSTRING_INDEX(displaypart, ' ', 3), ' ', -1) AS last_name
FROM tfsusers1

No comments:

Post a Comment