我不是很喜欢 MySQL... 似乎它不起作用。我曾希望至少能够像这样使用 ELT 遍历我的变量名:
ELT( loopcounter, passed_sizes )
循环计数器从 1,2,3... 开始,passed_sizes 是一个像 'S','M','L','XL' 这样的字符串,但我想你也不能构造这样的元素。
所以我最终做了过多代码的解决方案:
BEGIN
SELECT art.a, art.v, art.c
FROM arts AS art
WHERE ( (filter = '') AND (1=1)
OR art.d = filter
)
AND ( (size_1 = '') AND (1=1) OR ( art.size = size_1 AND art.qty >= qty_1 ) )
AND ( (size_2 = '') AND (1=1) OR ( art.size = size_2 AND art.qty >= qty_2 ) )
AND ( (size_3 = '') AND (1=1) OR ( art.size = size_3 AND art.qty >= qty_3 ) )
AND ( (size_4 = '') AND (1=1) OR ( art.size = size_4 AND art.qty >= qty_4 ) )
AND ( (size_5 = '') AND (1=1) OR ( art.size = size_5 AND art.qty >= qty_5 ) )
AND ( (size_6 = '') AND (1=1) OR ( art.size = size_6 AND art.qty >= qty_6 ) )
AND ( (size_7 = '') AND (1=1) OR ( art.size = size_7 AND art.qty >= qty_7 ) )
AND ( (size_8 = '') AND (1=1) OR ( art.size = size_8 AND art.qty >= qty_8 ) )
AND ( (size_9 = '') AND (1=1) OR ( art.size = size_9 AND art.qty >= qty_9 ) )
AND ( (size_10 = '') AND (1=1) OR ( art.size = size_10 AND art.qty >= qty_10 ) )
GROUP BY art.a, art.v, art.c
HAVING anzahl = length;
END
并传入 22 个参数而不是两个字符串。可读但男孩我想念易于使用的循环......如果有人知道更简单的实现,请发布作为答案。谢谢!