做我正在尝试的正确方法是什么?发现Check IN可以满足我的需求。
$hierarquia = implode(",", $_POST['hierarquia']);
// Show: 3,4
(
SELECT planoDeConta FROM `financ_receita`
WHERE data BETWEEN '2011-01-01' AND '2013-12-30'
planoDeConta IN ($hierarquia)
) UNION ALL (
SELECT planoDeConta FROM `financ_despesa`
WHERE data BETWEEN '2011-01-01' AND '2013-12-30'
planoDeConta IN ($hierarquia)
)
最佳答案
您有一个语法错误,因为在每个查询的第二个条件之前缺少连词:
(
SELECT planoDeConta
FROM `financ_receita`
WHERE data BETWEEN '2011-01-01' AND '2013-12-30' AND
planoDeConta IN ($hierarquia)
) UNION ALL (
SELECT planoDeConta
FROM `financ_despesa`
WHERE data BETWEEN '2011-01-01' AND '2013-12-30' AND
planoDeConta IN ($hierarquia)
)
这应该起作用,因为您正在“查询字符串”级别用
$hierarquia
进行变量替换。如果仅将值输入为字符串,则它将不起作用。