--1计算100天后病毒发作的日期。
print convert(varchar(50),dateadd(day,100,getdate()),111)
--2凡是入职一年以上的员工,工资增加500¥
update Employees set EmpSalary=EmpSalary+500 where DATEADD (YEAR ,1,EmpInTime)<GETDATE()
--3计算1975年10月5日到现在现在相差多少年/月/日/小时?
print datediff(year ,1975-10-15,getdate())
print datediff(month ,1975-10-15,getdate())
print datediff(day,1975-10-15,getdate())
print datediff(hour ,1975-10-15,getdate())
--4统计2008年入职的员工
select *from Employees where YEAR(EmpInTime)='2008'
--5输出所有数据中通话时间最长的5条记录。
select top 5*,通话时长=DATEDIFF(second,StartDateTime,EndDateTime)from CallRecords order by 通话时长 desc,CallerNumber desc
--1.1
--90分以上优秀
--80分以上良好
--70分以上中等
--60分以上及格
--60分以下不及格
Select scoreid,studentid,english,评级=Case When english>=90 then '优秀'When english>=80 then '良好'When english>=70 then '中等' When english >=60 then '及格'Else '不及格'End form score
--2、要求,查询结果集中有A B C三列,用SQL语句实现:当A列大于B列时,在C中显示A列的值否则显示B列中的值。
Select A,B,C=case when A>=B then A Else (b) End from TestCase
--3、 在订单表中,统计每个销售员的总销售金额,列出销售员名、总销售金额、称号(>6000金牌,>5500银牌,>4500铜牌,否则普通)
Use Test
Select * from MyOrders
Select salesAssistant AS 销售员,
SUM(saveNumber*savePrice) as 销售总金额,
称号=
Case
When SUM(saveNumber*savePrice)>6000 then'金牌'
When SUM(saveNumber*savePrice)>5500 then'银牌'
When SUM(saveNumber*savePrice)>4500 then'铜牌'
Else '普通'
End from MyOrders
--4.
单号 金额
Rk1 10
Rk2 20
Rk3 -30
Rk4 -10
将上面的表输出为如下的格式:
单号 收入 支出
Rk1 10 0
Rk2 20 0
Rk3 0 30
Rk4 0 10
Select Number as 单号,
支出=
case
When ammont>0 then ammont
else 0
end,
收入=
Case
When ammont<=0 then abs(amount)
Else 0
End
from 表名