簡體   English   中英

從出生日期計算年齡與年齡之間的條件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM