mysql 常用命令(一)
1. 函数向日期添加指定的时间间隔
DATE_ADD(date,INTERVAL expr type)
eg:DATE_ADD(CURDATE(),INTERVAL 1 MONTH) //在当前时间加一个月
2.计算年龄
eg:select birth ,CURDATE, YEAR(CURDATE())-YEAR(birth) - (RIGHT(MONTH(CURDATE),5) < RIGHT(MONTH(birth),5)) as age from pet; birth CURDATE age 1998-09-11 2003-08-19 4 YEAR() 获取年,MONTH() 获取月,day() 获取天
3.拥有某个列的最大值的行
eg:SELECT article, dealer, price FROM shop WHERE price=(SELECT MAX(price) FROM shop); eg:SELECT article, dealer, price FROM shop ORDER BY price DESC LIMIT 1;(假设有多个最大价格,那这个语句只能查找出一个)