我已计算出自出生日期的年龄,但我想仅在存储过程中选择大于55岁。以下是我的所作所为。
DELIMITER //
CREATE PROCEDURE p6()
BEGIN
SELECT Firstname, Lastname, telephone_number, TIMESTAMPDIFF(YEAR,DOB,CURDATE()) AS age
FROM Staff
WHERE Job_title = 'instructor';
END //
DELIMITER ;
答案 0 :(得分:0)
DELIMITER //
CREATE PROCEDURE p6()
BEGIN
SELECT Firstname, Lastname, telephone_number,
TIMESTAMPDIFF(YEAR,DOB,CURDATE()) AS age
FROM Staff
WHERE Job_title = 'instructor'
AND TIMESTAMPDIFF(YEAR,DOB,CURDATE()) > 55;
END //
DELIMITER ;
答案 1 :(得分:0)
MySQL有一个扩展程序,您可以使用having
来实现此目的:
SELECT Firstname, Lastname, telephone_number,
TIMESTAMPDIFF(YEAR, DOB, CURDATE()) AS age
FROM Staff
WHERE Job_title = 'instructor'
HAVING age > 55;