图表统计数据
Sql函数调用
项目记录
劳务实名制系统首页数据统计
应用到的SQL Server 函数
函数 | 案例 | 说明 |
---|---|---|
DATEDIFF(part,start,end) | select * from [表名] where DateDiff(dd,[字段DT],getdate())<=7 |
七天内的数据 |
CONVERT(varchar(20), date, 23) | select CONVERT(varchar(12) , getdate(), 23 ) |
2020-05-25(格式转换) |
聚合函数 | COUNT、SUM、MIN 和 MAX |
求记录数,求和,最小值,最大值 |
Case函数 | case type when '1' then '进场' else '退场' end |
条件判断 |
SQL Server查询语句
本月新开,本月退场,在建项目,工人总数
Select
(Select COUNT(Fid) from SM_Project where DATEDIFF(dd,startDate,GETDATE())>0 and DATEDIFF(dd,startDate,GETDATE())<30 ) 本月新开,
(Select COUNT(Fid) from SM_Project where DATEDIFF(dd,completeDate,GETDATE())>0 and DATEDIFF(dd,completeDate,GETDATE())<30 ) 本月退场,
(Select COUNT(Fid) from SM_Project where DATEDIFF(dd,completeDate,GETDATE())<0 ) 在建项目,
(select COUNT(Fid) from SM_ProjectWorker ) 工人总数
查询30天内工人考勤情况
select COUNT(*) as 考勤人数,日期
from
(Select CONVERT(varchar(100), date, 23) as 日期,workerFid
from SM_WorkerAttendance where DateDiff(dd,date,getdate())<=30
group by CONVERT(varchar(