我有一个列,值可以是x y或z,我的语法有问题。如果某个值是x或y以及其他参数,我想在计数中添加一个。我相信我的“或者”陈述是什么让我错误的数据。
示例:
受试者
X
ý
ž
X
我希望计数为3
$query = "SELECT COUNT(*) as c FROM DATA
WHERE Assign_To = ('data')
AND
Date_Entered >= ('3/21/2015')
AND
Date_Entered <= ('3/22/2015')
AND
columnname = ('x')
OR
columnname = ('y')";
答案 0 :(得分:0)
将OR括在括号中
$query = "SELECT COUNT(*) as c FROM DATA
WHERE Assign_To = ('data')
AND Date_Entered >= ('3/21/2015')
AND Date_Entered <= ('3/22/2015')
AND ( columnname = 'x' OR columnname = 'y' )";
其他一些建议: 您不必将所有内容包装在括号中,并在输入日期之间使用between语句。介于两者之间。此外,由于两个OR选项都针对相同的字段,因此您可以使用IN来代替
$query = "SELECT COUNT(*) as c FROM DATA
WHERE Assign_To = 'data'
AND Date_Entered BETWEEN '3/21/2015' AND '3/22/2015'
AND columnname in ( 'x', 'y' )";