㈠ 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 急求工龄计算语句
写了一个函数,可以帮助大家 计算工龄。调用方式 select fn_GetWorkYear('2015-10-10','2019-03-20')。
create function [dbo].[fn_GetWorkYear]
(
@beginday datetime, --开始日期
@endday datetime --结束日期
)
returns int
as
begin
if @beginday > @endday
begin
return 0;
end
declare @workyear int
select @workyear = datediff(year, @beginday, @endday)-1--年份差值
if datepart(month, @endday) > datepart(month, @beginday)--月份超过
begin
select @workyear = @workyear + 1
end
if datepart(month, @endday) = datepart(month, @beginday)--月份一样
begin
if datepart(day, @endday) >= datepart(day, @beginday)--日超过
begin
select @workyear = @workyear + 1
end
end
return @workyear ;
End
GO
㈢ 查询工作超过5年的员工信息的sql语句
SELECT 员工.姓名 form 员工 WHERE 员工.工作年限>5;
㈣ sql中如何提取从数据库中所获得时间的年份
SQL从时间字段值中获取年份使用DATENAME()函数。
DATENAME()函数语法:DATENAME(param,date)。
date是时间字段名 或一个时间值param是指定要返回日期部分的参数,包括下面几种:
获取年份就可以这样写 datename(year,date) 或 datename(yy,date) 。
已系统当前时间getdate()为例,3种写法获取年份。另外,DATENAME返回的是一个字符串,如果需要返回整数,可以使用DATEPART ( datepart , date ) ,语法与DATENAME相同。
获取日期字段的年select to_char(sysdate,'yyyy') as year from al或者:(指定日期)select to_char(to_date('2013/08/08','yyyy/mm/dd'),'yyyy') as year from al
获取日期字段的月select to_char(sysdate,'mm') as month from al
获取日期字段的日select to_char(sysdate,'dd') as day from a
㈤ sql查询数据,好多都需要按年份查询,按年份查数据有哪几种方式呢
本人时间戳都不知道是什么东西i,网络看了一下,还是不懂,惭愧呀!
你可以打开sql 2005在联机帮助中搜一下,有很多函数。
我知道其中有一个很有用,DATEDIFF ( datepart , startdate , enddate ):
Returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.就是用于在startdate和enddate年份之间数据不是连续存在的情况,举个联机帮助上的例子吧,希望能帮到你,我是学生可能没有经验:
CREATE TABLE dbo.Duration
(
startDate datetime2
,endDate datetime2
)
INSERT INTO dbo.Duration(startDate,endDate)
VALUES('2007-05-06 12:10:09','2007-05-07 12:10:09')
SELECT DATEDIFF(day,startDate,endDate) AS 'Duration'
FROM dbo.Duration;
-- Returns: 1
㈥ 怎么在sql中 查询1年的数据
近一年分三种情况,以当前时间为中心,前后各半年;以当前时间为最后时间,查询当前时间前一年的数据;以当前时间为起始时间,查询后一年的数据。
语法分别如下:
1、以当前时间为中心,前后各半年
1
select * from 表名 where 时间字段 between dateadd(DAY,(-364/2),GETDATE()) and dateadd(DAY,(364/2),GETDATE());
2、以当前时间为最后时间,查询当前时间前一年的数据
1
select * from 表名 where 时间字段 between dateadd(DAY,-365,GETDATE()) and GETDATE() ;
3、以当前时间为起始时间,查询后一年的数据
1
select * from 表名 where 时间字段 between GETDATE() and dateadd(DAY,365,GETDATE());
㈦ sql怎么按年月查询
按年:
select * from table where substring(convert(varchar(30),时间字段,120),1,4)='2013'
按月:
select * from table where substring(convert(varchar(30),时间字段,120),1,7)='2013-03'
欢迎追问
㈧ 查询每个部门中的员工数量、平均工资和平均工作年限,sql语句,Oracle数据库。
--平均服务来期限(单位为年)源
select
deptno,trunc(avg((sysdate-hiredate)/365),0)
"平均工作年限"
from
emp
group
by
deptno;
--不满一年算一年
select
deptno,trunc(avg(trunc((sysdate-hiredate)/365,0)),0)
"平均工作年限"
from
emp
group
by
deptno;
--不满一年不算
㈨ sql查询工龄大于或等于10年的员工信息
select *
from 表
where datediff(yy,开始工作日期,getdate()) >= 10
㈩ SQL查询日期的年份
要返回正确的记录,你需要适用日期和时间范围。有不止一种途径可以做到这一点。例如,下面的这个SELECT 语句将能返回正确的记录: SELECT * FROM weblog WHERE entrydate>=”12/25/2000” AND entrydate<”12/26/2000” 这个语句可以完成任务,因为它选取的是表中的日期和时间大于等于12/25/2000 12:00:00:000AM并小于12/26/2000 12:00:00:000AM的记录。换句话说,它将正确地返回2000年圣诞节这一天输入的每一条记录。 另一种方法是,你可以使用LIKE来返回正确的记录。通过在日期表达式中包含通配符“%”,你可以匹配一个特定日期的所有时间。这里有一个例子: SELECT * FROM weblog WHERE entrydate LIKE ‘Dec 25 2000%’ 这个语句可以匹配正确的记录。因为通配符“%”代表了任何时间。