當前位置:首頁 » 編程語言 » 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
呵呵,希望能有幫助,^_^