我有以下查询:
$query4 = $db->query("SELECT count(codes.lcfruh) AS front_lcfruh, kw, datum, GROUP_CONCAT(name) AS name FROM codes
RIGHT JOIN dienstplan ON (dienstplan.schicht = codes.lcfruh OR dienstplan.schicht = codes.lcteildienst OR dienstplan.schicht = codes.lcshteil)
RIGHT JOIN personal ON personal.perso_id = dienstplan.perso_id
WHERE personal.status_sum = 'rezeption' AND dienstplan.schicht!='' AND dienstplan.kw = '$kw' AND personal.zeigen='ja'
GROUP BY dienstplan.datum");
我希望有7个输入字段的结果(一周中的每一天)。这是正确的。列出两个0或值大于0的字段,实际上创建了输入字段。
while ($result = $query4 ->fetch_object()) {
echo '<p class="taglist1"><input name="" type="text" title="'.$result->name.'" class="zbroj'.$result->front_lcfruh.'" value="'.$result->front_lcfruh.'"></p>';
}
在标题中,如果它们具有一定的值,我想列出名称,这同样有效,直到我在代码中的代码中添加以下行 WHERE CLAUSE
AND (dienstplan.schicht = codes.lcfruh OR dienstplan.schicht = codes.lcteildienst OR dienstplan.schicht = codes.lcshteil)
在这种情况下,问题如下:结果未显示不匹配的字段,我应该在其中count(codes.lcfruh)=0
。不匹配的字段不会显示。
我是否有可能将这一行放在代码中的其他位置,以便也获得列出的空字段。
您要放入该where
子句中的代码是:
AND (dienstplan.schicht = codes.lcfruh OR
dienstplan.schicht = codes.lcteildienst OR
dienstplan.schicht = codes.lcshteil
)
虽然你不打算为这是事实,这也增加了条件:
dienstplan.schicht is not null and
(codes.lcfruh is not null or dienstplan.schicht is not null OR dienstplan.schicht is not null)
因为NULL
值在中被视为false where
。这“撤消”了right outer join
。
解决方案是将条件移到该on
子句。或者,您可以添加其他or
子句来指定该NULL
值是可以的值。
编辑:
尝试将where
子句更改为:
AND (dienstplan.schicht = codes.lcfruh OR
dienstplan.schicht = codes.lcteildienst OR
dienstplan.schicht = codes.lcshteil OR
dienstplan.schicht is null or
(codes.lcfruh is null and codes.lcteildienst is null and codes.lcshteil is null)
)
这将保留失败的行right outer join
。
编辑二:
下一个想法。将条件移到group_concat()
。如果第一个查询有效,则可能是您想要的:
GROUP_CONCAT(case when dienstplan.schicht = codes.lcfruh OR
dienstplan.schicht = codes.lcteildienst OR
dienstplan.schicht = codes.lcshteil
then ''
else name
end)
如果这不起作用,请使用示例数据和所需结果编辑您的问题。
编辑三:
这是你想要的吗?
SELECT count(case when personal.status_sum = 'rezeption' AND dienstplan.kw = '52'
then codes.lcfruh
end) AS front_lcfruh,
kw, datum,
GROUP_CONCAT(case when personal.status_sum = 'rezeption' AND dienstplan.kw = '52'
then name
end) AS name
FROM codes
RIGHT JOIN dienstplan ON (dienstplan.schicht = codes.lcfruh)
RIGHT JOIN personal ON personal.perso_id = dienstplan.perso_id
GROUP BY dienstplan.datum;
我将条件移到该select
语句中,因此所有行都会出现。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句