0

这是我的 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'
4

2 回答 2

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
于 2013-01-10T12:59:57.003 回答
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中不允许您使用的内容

于 2013-01-10T13:00:07.363 回答