我想在兩天中減去在session ='morning'中輸入的anem_reading值,i.date = today和x.date昨天值顯示爲'run',但sql中出錯代碼是THREMysql - 從前一天減值減值
SELECT x.date,
i.anem_reading - (SELECT anem_reading
FROM reg_data x
WHERE date = DATE_SUB(now(), INTERVAL 1 DAY)
AND x.(session=morning) = (i.session=morning)
ORDER BY date
LIMIT 1) run FROM reg_data i;
CREATE TABLE `reg_data` (
`date` varchar(10) NOT NULL,
`session` varchar(10) NOT NULL,
`time` time default NULL,
`temp_air` float NOT NULL,
`rel_humid` float NOT NULL,
`soil_temp_5` float NOT NULL,
`soil_temp_20` float NOT NULL,
`soil_temp_30` float NOT NULL,
`soil_temp_60` float NOT NULL,
`air_pressure` float NOT NULL,
`anem_reading` float NOT NULL,
`dry_temp` float NOT NULL,
`wet_temp` float NOT NULL,
PRIMARY KEY (`date`,`session`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
是'FLOAT'一個德爾iberate選擇? – Strawberry
我不認爲'i.anem_reading - (select X)FROM FROM'什麼都是有效的MySQL語法。你缺少部分查詢或有一些括號問題? (甚至只是誤解'AS運行')? – 2013-11-15 17:07:59
@ebyrob是的這是myquery請給我幫助godd查詢 – user2986352