效率不是问题,前提是你的查询语句。 在表中严格禁止创建类似年龄这样的字段。这样会导致不符合范式。计算年龄,这个要看你的年龄规定是什么。周岁? 整数? 还是要精确到小数? 最简单的粗略算法就是直接减得到天,然后再除 365. select DATEDIFF(curdate(),datecolumn)/365 as Age from table1.
搜索时,应该使用的语句是比如查找 10 - 20 岁之间 where datecolumn between curdate()-interval 20 year and curdate-interval 10 year这样可以利用索引。
select DATEDIFF(curdate(),datecolumn)/365 as Age from table1.
where datecolumn between curdate()-interval 20 year and curdate-interval 10 year这样可以利用索引。
接上面的一条回复,用where age between 10 and 20,是么?感谢。
OR
在插入的TRIGGER中
SET NEW.年龄=...
age是别名,不是新加的列哈。