在mysql表中只知道出生年份,要求查詢18 22歲之間的人

2021-04-15 10:52:24 字數 1500 閱讀 9420

1樓:匿名使用者

只有年份只能粗略計算年齡了,請參見下列語句

select * from tblname where year(now())-birth between 18 and 22;

2樓:匿名使用者

select * from

[表名抄]

where

[出生日期

襲欄位名] between date_add(now(),interval -22 year) and date_add(now(),interval -19 year);

按照bai出生年月du日計算來取zhi 小dao22大19的人

mysql中根據輸入的年齡查詢符合該年齡出生日期的資料

3樓:匿名使用者

string sql = "select * from teacher where to_char(sysdate,'yyyy')-to_char(birthday,'yyyy') = " +key+" \n";

用sql語句檢索出年齡大於等於18小於等於20的學生姓名和性別

4樓:4終

1、首先,在sc表中找到學了c2的學生學號。

2、然後,就可以設定投影列和資料來源。

3、此時,就可以在這裡進行兩層關係的連線。

4、這個時候可以利用【=any】的方式進行判斷是否在這個集合之中。

5、最後【=any】和【in】兩個的用法其實基本相同,只要有一個滿足就是滿足。

5樓:匿名使用者

使用函式:between 、getdate()、datediff()

函式說明:

1/between:檢索數字型別或時間型別的區間記錄

2/getdate():獲得當前計算機時間

3/datediff():計算兩個時間之間的差值,可以計算年、月、日、時、分、秒、毫秒等

其他說明:sql在檢索區間資料時可以使用大於等於,小於等於,或between函式

示例:(假設表名:table,出生日期 列名:col)多數都是儲存的出生日期,很少直接儲存年齡的

--第1種方法:

select * from table where datediff(yyyy,col,getdate()) between 18 and 20

--第2種方法:

select * from table where datediff(yyyy,col,getdate())>=18 and datediff(yyyy,col,getdate())<=20

6樓:溜鬚拍馬關雲長

select sname,*** from s where sage between 18 and 20

7樓:匿名使用者

select sname,*** from s where sage>=18 and sage<=20

如何在mysql的表中的欄位中刪除內容中包含的指定字串

update 表名 來 set 欄位 自名bai concat left 欄位名 du,instr 欄位名zhi,1 right 欄位名,length 欄位名 instr 欄位名,where instr 欄位名,0 and instr 欄位名,instr 欄位名,看得dao懂吧 instr 欄位名,...

mysql查詢表中是否有某個欄位

information schema.columns這表bai儲存了所 du有欄位資訊 zhiselect count from information schema.columnswhere table schema world and table name city and column nam...

MySQL怎麼通過表中的ID值查詢這個ID下的其他欄位的

sql語句如下 select user from table 你的表名 where id 5 這樣就可以查詢過來id為5的這條資料記錄的user的值 sql 怎樣根據一個表種的欄位id 查出 另一個表中的 資料 20 例如 兩個表中 的news type id 跟 type id是對應的,根據new...