我有两个表希望两个表使用日期加入,但查询有错误
CREATE TABLE `reg_data3` (
`date` date NOT NULL,
`time` time NOT NULL,
`rainfall` float default NULL,
`evep` float default NULL,
`max_temp` float default NULL,
`min_temp` float default NULL,
`sunshine_hrs` float default NULL,
PRIMARY KEY (`date`)
)
ENGINE=MyISAM
DEFAULT CHARSET=latin1;
CREATE TABLE `velocity` (
`date` date NOT NULL,
`run` float NOT NULL,
`velocity` float NOT NULL
)
ENGINE=MyISAM
DEFAULT CHARSET=latin1;
查询是
SELECT
A.date,
A.rainfall,
A.evep,
A.max_temp,
A.min_temp,
A.sunshine_hrs,
B.run,
B.velocity
FROM
reg_data3 A
INNER JOIN velocity B
ON A.date = B.date
WHERE
year(DATE_FORMAT(date, '%y-%m-%d'))='2008' AND
month(DATE_FORMAT(date, '%y-%m-%d'))='04'
ORDER BY
A.date ;`
显示错误= column 'date' in where clause is ambiguous
答案 0 :(得分:0)
这是你的
DATE_FORMAT(date, '%y-%m-%d')
在WHERE语句中的部分,您需要量化日期列(A或B.),就像您在其他地方一样