在数据库中怎么编写查询年龄在20——30岁之间的会员的sql语句

在数据库中怎么编写查询年龄在20——30岁之间的会员的sql语句,第1张

select 

from 会员

where 年龄>=20 and 年龄<=30

“elect from 学生信息 where age between 18 and 20”此句sql最前面少个s

应该是 select from 学生信息 where age between 18 and 20 意思是 

在学生信息中找年龄在18到20的学生所有字段信息。

1

select sno,sname from s where ssex='女' and sage=19

2

select cname,clocation from c where clocation='主楼' order by teacher

3

select sno from sc where grade>=80 and cno in (select cno from c where cname='数据库原理')

4

select ssno,ssname,avg(grade) from s,c,sc where ssno=scsno and ccno=sccno group by ssno,ssname

5

selete from sc where cno in (select cno from sc group by cno having count()<=10)

我简单给你列点数据

create table student(id int,name varchar(10),birthday datetime)

insert into student values (1,'张三','1988-01-01')

insert into student values (2,'李四','1987-09-22')

insert into student values (3,'王五','1986-12-25')

执行

select avg(datediff(year,birthday,getdate())) as 平均年龄 from student

结果

给你说明下

getdate()就是当前时间

datediff(year,birthday,getdate())  这个datediff函数就是求两个时间之间的时长的函数,其中,birthday就是生日那列,getdate就是当前时间,算出两个时间之间的year就是年龄

至于avg就是求平均数了

要是你想汇总年龄总和的话用sum函数即可,如下

select sum(datediff(year,birthday,getdate())) as 平均年龄 from student

以上就是关于在数据库中怎么编写查询年龄在20——30岁之间的会员的sql语句全部的内容,包括:在数据库中怎么编写查询年龄在20——30岁之间的会员的sql语句、分别用一条SQL语句完成以下题目的 *** 作: 1. 查询年龄为19岁的女同学的学号和姓名、SQL 年龄汇总查询等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9441386.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存