SQL查询【根据生日计算】
根據(jù)生日日期,獲取當(dāng)前年齡、年齡單位。
Select Case when DateDiff(Year, BirthDate, GetDate()) > 0 then DateDiff(Year, BirthDate, GetDate())
? ? ? ? ? ? ? ? ? ? when DateDiff(Month, BirthDate, GetDate()) > 0 then DateDiff(MONTH, BirthDate, GetDate())
? ? ? ? ? ? ? ? ? ? When DATEDIFF(DAY, BirthDate, GetDate()) > 0 then DateDiff(DAY, BirthDate, GetDate()) end Age,
? ? ? ? ? ?Case When DateDiff(Year, BirthDate, GetDate()) > 0 then '歲'
? ? ? ? ? ? ? ? ? ? When DateDiff(Month, BirthDate, GetDate()) > 0 then '月'
? ? ? ? ? ? ? ? ? ? When DATEDIFF(DAY, BirthDate, GetDate()) > 0 then '日' end AgeUnit, BirthDate BirthDate
From 人員信息表
轉(zhuǎn)載于:https://www.cnblogs.com/meitai/p/9175782.html
總結(jié)
以上是生活随笔為你收集整理的SQL查询【根据生日计算】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Day10 Python基础之特殊函数(
- 下一篇: 我的探究:为什么.h头文件中不要写usi