worker(workerno,workername,workersex,workerborndate)
显示所有职工的年龄,并按职工号递增排序。
表中只有员工的出生时间,例如1952-01-03
此sql语言如何写?如何利用系统时间计算年龄?
请高手帮忙1
SQL code:
select workerno,workername,workersex,datediff(year,workerborndate,getdate())
from worker
order by workerno
SQL code:
select workerno,workername,workersex,datediff(year,workerborndate,getdate())+1 as age
from worker
order by workerno
SQL code:
if OBJECT_ID('worker') is not null
drop table worker
go
--worker(workerno,workername,workersex,workerborndate)
create table worker(
workerno int,
workername varchar(20),
workersex int,
workerborndate datetime
)
insert into worker
select 3,'pjl',1,'1987-11-02' union all
select 2,'kzd',1,'1988-11-11' union all
select 1,'dyx',1,'1986-01-11'
select * from worker
select workerno,workername,workersex,DATEDIFF(MONTH,workerborndate,GETDATE())/12 as age
from worker
order by workerno
/*
就这样结贴啦?
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......