在sql中如何找出和“任伟”年龄一样大的学生的姓名

来源:百度知道 编辑:UC知道 时间:2024/06/14 14:13:22
主要是怎样定义“任伟”年龄?
虽然运行不成功,但还是很感谢你的意见!

因为时间的推移,年龄如果单独作为一个字段,是不合理的。所以一般地,表中存储的是出生日期相关的信息。
可以这么写
table name : student_info
column name : birthday , student_name
column type : varchar2(8) --YYYYMMDD
sql command:
select * from student_info where substr(birthday,1,4) = (select substr(birthday,1,4) from student_info where student_name = '任伟')
-- 这里,我觉得你用名字来作为判定是有隐患的,建议使用表的主键