这是我的Mysql查询
DELIMITER $$
USE `divineproposal_db`$$
DROP PROCEDURE IF EXISTS `pr_Search_Profile`$$
CREATE DEFINER=`root`@`%` PROCEDURE `pr_Search_Profile`(IN vGender CHAR(1),IN vMinAge INT,IN vMaxAge INT,IN vReligion INT)
BEGIN
SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), cpl_DateofBirth)), "%Y")+0 AS Age FROM tbl_candidateprofile
WHERE Age>= vMinAge AND Age<=vMaxAge;
END$$
DELIMITER ;
错误::
Unknown column 'Age' in 'where clause'
答案 0 :(得分:0)
您不能在WHERE
子句中使用别名,因此您必须使用子查询或重用age
的定义:
select Age
from
(
SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), cpl_DateofBirth)), "%Y")+0 AS Age
FROM tbl_candidateprofile
) src
WHERE Age>= vMinAge
AND Age<=vMaxAge;
或者:
SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), cpl_DateofBirth)), "%Y")+0 AS Age
FROM tbl_candidateprofile
WHERE DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), cpl_DateofBirth)), "%Y")+0>= vMinAge
AND DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), cpl_DateofBirth)), "%Y")+0<=vMaxAge
答案 1 :(得分:0)
试着像这样使用 -
SELECT * FROM tbl_candidateprofile
WHERE DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), cpl_DateofBirth)), "%Y")+0>= vMinAge AND DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), cpl_DateofBirth)), "%Y")+0<=vMaxAge;
Mysql中不允许使用您的内容