自已的sql server练习小记
print getdate();
print datediff(year,'1987-09-13',getdate())
select * from CallRecords
select top 5 *,'通话时间(秒)'=DATEDIFF(s,CallRecords.StartDateTime,CallRecords.EndDateTime)
from CallRecords order by '通话时间(秒)' desc
select 'jian',* from CallRecords
select SUM(t1.通话时间) from(
select 通话时间=DATEDIFF(s,CallRecords.StartDateTime,CallRecords.EndDateTime) from CallRecords where TelNum like '0%'
) as t1
print datepart(year,getdate())
select top 3 CallerNumber,
通话时间=sum(datediff(s,startDateTime,endDatetime))
from CallRecords
where DATEDIFF(mm,StartDateTime,'2010-07-12')=0
group by CallerNumber
order by 通话时间 desc
select top 3 CallerNumber,
通话次数=COUNT(CallRecords.Id)
from CallRecords
where DATEDIFF(mm,StartDateTime,'2010-07-12')=0
group by CallerNumber
order by 通话次数 desc