当前位置:首页 » 编程语言 » sql查找年龄90年以后的同学
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql查找年龄90年以后的同学

发布时间: 2023-03-05 18:19:50

① 用sql命令查询数据

select * frm spec

② 在SQL中查询年纪一样大(出生年份一样)的两个不同学生的姓名,以及他们的年龄

--好歹给张表的截图啊
--创建student表
create table student
( s_id number
,s_name varchar2(20)
,s_birthday date
)
--导入三组数据
insert into student values('001','liuzhao',to_date('1992-04-02 01:01:01','yyyy-mm-dd hh:mi:ss'));
insert into student values('002','lisi',to_date('1992-04-02 01:01:01','yyyy-mm-dd hh:mi:ss'));
insert into student values('003','wangwu',to_date('1990-02-10 01:01:01','yyyy-mm-dd hh:mi:ss'))

--查询出生年份相同的学生姓名和年龄
select s_name ,to_number(to_char(sysdate,'yyyy'))-to_number(to_char(s_birthday,'yyyy')) age
from student
where to_char(s_birthday,'yyyy') in
(select to_char(s_birthday,'yyyy')
from student
group by to_char(s_birthday,'yyyy')
having count(1)>1)

③ 查询1990年以前出生的学生信息sql语句

查询1990年以前出生的学生信息sql语句:

select * from student where sage like “1990%”。

SQL的select语法:

用途:

从指定表中取出指定的列的数据。

语法:

SELECT column_name(s) FROM table_name

解释:

数据库中选取指定列,并允许从一或多个指定表中,选取一或多个指定列或指定行。SELECT 陈述式的完整语法相当复杂,但主要子句可摘要为:

SELECT select_list

[ INTO new_table ] FROM table_source

[ WHERE search_condition ] [ GROUP BY group_by_expression ] [ HAVING search_condition ]

[ ORDER BY order_expression [ ASC | DESC ] ]

(3)sql查找年龄90年以后的同学扩展阅读:

SQL常用技巧:

1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)

法一:select * into b from a where 1<>1

法二:select top 0 * into b from a

2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)insert into b(a, b, c) select d,e,f from b;

3、说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)

insert into b(a, b, c) select d,e,f from b in '具体数据库' where 条件

例子:..from b in '"&Server.MapPath(".")&"data.mdb" &"' where..

4、说明:子查询(表名1:a 表名2:b)

select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)

5、说明:显示文章、提交人和最后回复时间

select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b

6、说明:外连接查询(表名1:a 表名2:b)

select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c

7、说明:在线视图查询(表名1:a )
select * from (SELECT a,b,c FROM a) T where t.a > 1;

8、说明:between的用法,between限制查询数据范围时包括了边界值,not between不包括select * from table1 where time between time1 and time2select a,b,c, from table1 where a not between 数值1 and 数值2

9、说明:in 的使用方法

select * from table1 where a [not] in ('值1','值2','值4','值6')

10、说明:两张关联表,删除主表中已经在副表中没有的信息

delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

④ SQL 查询所有相同年龄的学生信息,并按年龄排序。

这样吧

select*from学生基本档案where年龄in(select年龄from学生基本档案groupby年龄havingcount(*)>1)

⑤ 用SQL查询学生年龄,显示学生编号、姓名和年龄, 年龄降序 排序

select 学生编号,姓名,年龄 from 表 where 年龄='35' order by 年龄 desc

⑥ 查询出生日期在1990年后的女生信息用sql语句写出来

select * from 表名称 where sex='女' and year(birthdate)>=1990
注意,最后与1990的比较,1990要按照数字进行比较,两边不能加单引号。

⑦ SQL中,如何查询年龄

日期函数,access与SQL Server是有一点区别的,
如果是access的话,
select * from 你的表名
where year(now())-year(出生日期) between 20 and 25
如果是SQL Server的话,
select * from 你的表名
where year(getdate())-year(出生日期) between 20 and 25
呵呵,希望能有帮助,^_^