0
道歉模糊的问题标题,但不能确定正确的措辞,请纠正,如果需要的话。mysql返回单行和多行状态
我有以下MySQL查询,它将几个我的表连接在一起。
select distinct(o.person),
o.job,
p.risk,
r.training,
case when c.datecompleted is null then 'no' else 'yes' end TrainingCompleted,
case when c.expirydate is null then '' else c.expirydate end expirydate
from
orgstructure o
join personrisks p on p.Person=o.person
right outer join risktraining r on r.risk=p.risk
left outer join coursescompleted c on c.course=r.training and c.person=o.person
where o.department='house keeping' and o.person <> ''
order by o.person desc
它产生如下的结果:
在结果,你可以看到,每一个风险有应对风险的两个训练方案。我想返回另一列status
,看起来每个训练和训练完成的字段,如果任一训练完成,然后状态good
其他状态bad
。所以对于每个风险,我的输出在这个例子中只有两行。如果没有任何培训已经完成,则显示任何training
价值是需要的。
理想输出:
如何修改这个查询来达到预期的效果。
在此先感谢。做