在MySQL中获取一个人的年龄 [英] Get Age of a person in MySQL

查看:223
本文介绍了在MySQL中获取一个人的年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在mysql中达到人的年龄

How can i get a Persons age in mysql

想象一下,我有一个带有member.id, member.month, member.year的表 现在,我需要在月份中确定会员的年龄.

Imagine i have a table with member.id, member.month, member.year Now i need to get age of a member in Months.

说:

member.month = 1 and member.year = 2000 

这意味着该成员的年龄为 126 ,因为 10 年等于 120 月和 6 月是 6 个月. 现在的结果是会员年龄为 126 月.

That would mean the age of this member is 126 because 10 Years equals 120 Months and 6 Months is 6 Months. Now the result is that the members age is 126 Month.

如何在MySql中完成

How can i do it in MySql

推荐答案

select YEAR(NOW())*12+MONTH(NOW()) - (member.year*12+member.month) +1;

要使答案产生126,我必须在表达式中加1.我不确定这是否有意义,但这仅取决于您要如何定义年龄.

To make my answer yield 126, I had to add 1 to the expression. I'm not sure that makes sense, but it just depends on how you want to define age.

这篇关于在MySQL中获取一个人的年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆