⑴ SQL 中怎麼根據出生日期算出年齡 然後用年齡查詢
sql是不能查詢的,php可以計算年齡
1、取得當前日期的時間
2、將sql中的出生日期換算成時間
3、當前日期時間-出生日期時間
4、將得到的數值轉換為年月日
⑵ 求助SQL語句。麻煩教教,要准確高的簡短SQL語句
1 select top 3 學號,姓名,高考分數 from 學生表 order by 高考分數 asc
2 select 學號,姓名 from 表名 where 姓名 like "%生"
3 select left(學號,2)as 入學時間,convert(decimal(18,2),avg(高考成績))as 平均成績 from 學生表 group by left(學號,2) oder by left(學號,2)
4 select * distinct form 表名
7 select floor(datediff(month,出生日期,getdate())/12)
11 select top 1 * from 員工表 order by 年齡
12 select * from 員工表 where 部門ID=(select 部門ID from 部門表 where 部門名稱='信息中心')
13 select deptName,count(eid) from Depttab inner join Employee on Depttab.deptId=Employee.deptid group by deptName where Employee.diaoRu
select deptName 部門名,b.人數 from Depttab a,(select deptid,count(eid) 人數 from Employee where diaoRu between '2006-02-18' and '2008-09-23' group by deptid) as bwhere a.deptid=b.deptid
14 delete 表名 where 年齡< "1955-01-01"
15 update 表名 set 工資= 工資+200 where 職稱 =『高級工程師』
⑶ sql語句查詢表中年齡最大的人的姓名
select a.姓名, a.出生年月日
from UserT a
where not exists (select 1 from userT b where b.出生年月日 < a.出生年月日)
---------不存在比本行出生年月日小的記錄,那麼得到的就是出生年月日最小的值,也就是說,年齡最大的。
或者select * from UserT a where a.出生年月日 = (select min(出生年月日) from userT)
查詢生日等於最小出生年月日的記錄
⑷ sql查詢每個系中年齡最大的人的姓名和年齡
select name,age
from table
where age=
(select max(age)
from table
group by 院系)
你看這個可以不,先把每個院系中的最大年齡查出來,
然後再通過子查詢找出這個最大年齡的人的姓名。
⑸ 檢索統計年齡段為0-30,30-60,60以上的人員數(用一條Sql語句)怎麼寫啊
簡單。
select t.q,y.a,u.z from
(select count(*) q from emp_employee e where e.age>=0 and e.age<30) t,---小於30
(select count(*) a from emp_employee e where e.age>=30 and e.age<60) y,---大於30小於60
(select count(*) z from emp_employee e where e.age>=60)u---大於60
⑹ 在資料庫中用sql語句怎麼查詢年齡大於20
如果表為sutdent,年齡欄位為age,則SQL語句如下:
select * from student where age>20;
執行即可查詢到所有年齡大於20的記錄
⑺ 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
呵呵,希望能有幫助,^_^
⑻ 用SQL語句查詢年齡分段的分組查詢 我的數據表格式如下
--不知道你要的是不是這樣的結果
CreatetableT
(
籍貫varchar(10),性別varchar(2),生日varchar(10)
)
insertintotvalues('四川','男','19890627')
insertintotvalues('新疆','男','19930711')
insertintotvalues('河南','男','19890623')
insertintotvalues('四川','女','19880512')
insertintotvalues('新疆','男','19950425')
insertintotvalues('河南','女','19800304')
Select籍貫,性別,
Sum(CaseWhen年齡<=20Then1Else0End)As[0-20歲(人)],
Sum(CaseWhen年齡Between21And40Then1Else0End)As[21-40歲(人)],
Sum(CaseWhen年齡Between41And60Then1Else0End)As[41-60歲(人)],
Sum(CaseWhen年齡>=61Then1Else0End)As[60歲以上(人)]
From
(
Select*,Year(GETDATE())-Year(convert(Datetime,生日))As年齡
Fromt
)s
GroupBy籍貫,性別
withrollup
⑼ 資料庫根據生日(birthday)查詢年齡大於N的員工,(日期轉換)寫SQL語句
給你舉個例子吧:
select from_unixtime((unix_timestamp(now())-unix_timestamp('2009-10-26 10-06-07')))
你可以直接放sql里運行, 例子中,有內兩個3個mysql函數:
其中from_unixtime()是將時間戳 (一串容能轉化成時間的數字串) 轉化為人能讀懂的時間格式;
unix_timestamp()則是相反作用,即將人能讀懂的時間轉化為時間戳形式;
now()則是獲取當前時間(默認是類似於2009-10-26 10-06-07);
為什麼要轉化成時間戳呢?因為這樣能准確,方便的對時間進行加減計算,然後再將時間戳轉化回來。
該條語句,運行的結果類似於1982-01-23 01:51:55 , 此時還需要將該數字減去1970,就是年齡了。
你可以根據自己存在資料庫中的時間格式進行變通,也許我這說的不一定是對的,但是希望能給你啟示,可以根據自己的數據來驗證
⑽ php mysql怎樣根據資料庫表中的出生日期搜索出年齡大於65歲的記錄
不知抄道你的語句報襲什麼錯,我認為你不應該使用right來取日期裡面的你、月、日,應該使用YEAR、MONTH、DAY函數
另外,你不能使用SELECT後面的別名作為WHERE的條件,必須使用資料庫表的欄位作為條件,你要獲取65歲以上的可以使用這樣:
WHERE csrq<MAKEDATE(YEAR(NOW())-65, DAYOFYEAR(NOW()))