Ver originalselect c.interno, c.mercado, p.total,CASE WHEN ((select max(mov.final) from movimientos mov where mov.interno= p.interno and mov.fechai = "2014-12-11") is null ) THENp.totalELSE (select max(mov.final) from movimientos mov where mov.interno= p.interno and mov.fechai = "2014-12-11")END as ttfrom paciente pinner join calificacion con p.interno = c.internowhere p.fecha = "2014-12-11";