标签:姓名 sele int 出生日期 select name rem var ima
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `uid` int(11) NOT NULL AUTO_INCREMENT, `birthday` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `uname` varchar(255) DEFAULT NULL, PRIMARY KEY (`uid`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of user -- ---------------------------- INSERT INTO `user` VALUES (‘1‘, ‘1995-08-05 22:57:49‘, ‘小波‘);
SELECT uname 姓名,CASE WHEN DATE_ADD(birthday,INTERVAL YEAR(NOW())-YEAR(birthday) YEAR)>=NOW() THEN YEAR(NOW())-YEAR(birthday)-1 ELSE YEAR(NOW())-YEAR(birthday) END 年龄 FROM user
注:本题我是采用MYSQL来作答。
标签:姓名 sele int 出生日期 select name rem var ima
原文地址:https://www.cnblogs.com/chenxiaobo/p/9452446.html