查询所有手术预约及相对应的安排,如果安排的pk不为null,则用逗号隔开(如果有多个)。中sql语句如下:

 

select distinct a.pk, a.surgeryName, a.clerkName, a.customerName, a.orderTime, b.forecastTime, b.pk surgery_pk,
case 
    when c.pk is not null then  (select group_concat(d.pk) from surgery_arrange d where d.surgery_order_fk=a.pk) 
    else null end surgery_arrange_pk 
from (surgery_order a left join surgery b on a.surgery_fk=b.pk) left join surgery_arrange c on a.pk=c.surgery_order_fk 
order by surgery_arrange_pk desc, a.orderTime asc 
limit 0,10

结果如下图所示: