如果图像被标记为活动并且有人点击链接,他们应该被带到活动图像,否则他们应该被带到(MAX)最近上传的图像。我的第一个选择有效,但不完全有效。
这是我的选择:
select
b.image_id, b.active, c.id as event_id
from event.dbo.lite() a
left outer join event.dbo.dia_tracker b on a.code = b.patient_id
and image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = {$patient->hex})
left outer join event.dbo.ev c on a.code = c.patient_id and c.task_id in ('WR','RC') and c.status<>0
where a.code = {$patient->hex}
这是我需要一些帮助的新选择。
select
image_id,
active,
case when active <>1 than image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = 'DSMA')
from event.dbo.dia_tracker
where active = '1' and image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = 'DSMA')
自动取款机有点乱。我在想我可以使用 isnull 以更少的代码行完成更多工作。
更新:
select
*,
ISNULL(active,image_id) as image
from event.dbo.dia_tracker
where active = '1' and image_id = (select max(image_id) from event.dbo.dia_tracker where patient_id = 'DSMA')
仍然需要帮助。