[英]Calculating age from date of birth with between condition on age
我正在使用 MySQL 像這樣計算年齡
SELECT timestampdiff(year, md.birthDate, curdate()) as age
from user
WHERE age BETWEEN 10 and 20
但我想獲取年齡和 MySQL 之間的數據,顯示“年齡”的未知列,那么我該如何設置條件?
變體 1(表達式代替 output 名稱):
SELECT timestampdiff(year, md.birthDate, curdate()) as age
from user md
WHERE timestampdiff(year, md.birthDate, curdate()) BETWEEN 10 and 20
變體 2(有而不是 WHERE):
SELECT timestampdiff(year, md.birthDate, curdate()) as age
from user md
HAVING age BETWEEN 10 and 20
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.