我有体脂前测和后测的数据。如果后测值大于前测值,则只能大 2%,否则我不希望它出现在结果中。后测值可以是比前测低的任何数量。
此查询仅在两个值彼此相差 2% 以内时有效。缺失的部分是后测低于前测时。任何帮助,将不胜感激!
SELECT LPAD( `studid` , 7, '0' ) AS studid,
bodpoints,
STR_TO_DATE(TestDate, '%m/%d/%Y') AS testd
FROM bodpod, points
WHERE ABS((post - pre) / pre) <= '0.02'
AND ID2 = 'fall'
AND studid != ''
GROUP BY studid
HAVING COUNT( DISTINCT ID1 ) >=1 AND YEAR( testd ) = '2013'