我正在执行SELECT语句,并且有一个问题。当您这样做时,例如:
select max(BMI), STDDEV(WEIGHT) FROM MEASUREMENTS where
MEASUREMENTS.patient_id='nick' AND
MEASUREMENTS.measure_date BETWEEN DATE_SUB("2013-12-30", INTERVAL 6 YEAR) AND "2013-12-30";
也将0的行也算在内吗?如果是这样,我如何排除它们?因为就我而言,0表示“当天未进行度量”,所以我不想将这一天包括在我的结果总数中。
最佳答案
请尝试以下操作:排除值为零的行。
您的原始声明
select max(BMI), STDDEV(WEIGHT) FROM MEASUREMENTS where MEASUREMENTS.patient_id='nick' AND MEASUREMENTS.measure_date BETWEEN DATE_SUB("2013-12-30", INTERVAL 6 YEAR) AND "2013-12-30";
您的新声明
select max(BMI), STDDEV(WEIGHT) FROM MEASUREMENTS where MEASUREMENTS.patient_id='nick' AND MEASUREMENTS.measure_date BETWEEN DATE_SUB("2013-12-30", INTERVAL 6 YEAR) AND "2013-12-30" AND MEASUREMENTS.WEIGHT <> 0;
您只需添加
AND MEASUREMENTS.WEIGHT <> 0
。您也可以使用大于0的值。关于mysql - MySQL和“计数”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53008007/