当前位置:首页 » 编程语言 » 大神解说sql
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

大神解说sql

发布时间: 2023-06-16 12:02:31

A. 刚学sql数据库就怎么那么复杂的例子看不懂求大神解释

请参阅下面的文章,主要是讲述如何使用命令创建数据库,

在sql命令有指定文件路径 文件组 大小

使用sql脚本创建数据库

如果有疑问,请及时沟通

请采纳!

B. 一段很复杂很复杂的SQL语句。。求大神解释。。。

Select
*
From
(
Select
*
From
(
Select
Number
,ChineseName
,tb1.DepartmentCode
,DepartmentName
,ShiftId
,ShiftName
,Degree
,AskForLeaveType
,WorkOnDate
,OnDutyType
,StartTime
,EndTime
,AOnDuty
,AOffDuty
,Allday
,tb1.SumTotal
,'Error'=
Case
WhenDegree=1ANDStartTime<=AOnDutyANDEndTime<=AOnDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=1ANDStartTime>=AOffDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=1ANDStartTime>=WorkOnDate+''+'12:30'ANDEndTime<=WorkOnDate+''+'13:30'ANDCharindex('常白班',ShiftName)>0ANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=2ANDStartTime<=AOnDutyANDEndTime<=AOnDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=2ANDStartTime>=AOffDutyANDEndTime<=BOnDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=2ANDStartTime>=BOffDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=3ANDStartTime<=AOnDutyANDEndTime<=AOnDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=3ANDStartTime>=AOffDutyANDEndTime<=BOnDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=3ANDStartTime>=BOffDutyANDEndTime<=COnDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenDegree=3ANDStartTime>=COffDutyANDShiftId>0ANDLeft(AskForLeaveType,1)='0'Then0
WhenShiftId=0ANDLeft(AskForLeaveType,1)='0'Then0
WhenShiftId>0ANDLeft(AskForLeaveType,1)<>'0'ANDLeft(OnDutyType,1)=0Then0
WhenShiftId>0ANDLeft(AskForLeaveType,1)<>'0'ANDLeft(OnDutyType,1)=2ANDAskForLeaveType='出差假'Then0
WhenShiftId>0ANDLeft(AskForLeaveType,1)<>'0'ANDLeft(OnDutyType,1)=2ANDAskForLeaveType='产假'Then0
WhenShiftId=0ANDLeft(AskForLeaveType,1)<>'0'ANDConvert(varchar(10),StartTime,108)='00:00:00'ANDConvert(varchar(10),EndTime,108)='00:30:00'Then0
Else
1
End
From
(
Select
Number
,ChineseName
,DepartmentName
,d.DepartmentCode
,p.ShiftId
,p.ShiftName
,Degree
,AskForLeaveType
,Convert(varchar(10),WorkOnDate,120)as'WorkOnDate'
,StartTime
,EndTime
,AllDay
,SumTotal
,CaseWhenRight(Convert(Varchar(10),WorkOnDate,120),5)IN(selectRight(Convert(Varchar(10),HolidayDate,120),5)FromAttendanceHoliday)THEN'2-公众假上班'ELSE'0-平时上班'ENDAS'OnDutyType'
,CaseWhenLeft(FristBrushDate,1)='1'ANDConvert(varchar(10),AOffDuty,120)>Convert(varchar(10),AOnDuty,120)ThenCAST(Convert(Varchar(11),Dateadd(dd,-1,OnDutyDate),120)+Convert(Varchar(5),AOnDuty,108)ASDateTime)ELSECAST(Convert(Varchar(11),OnDutyDate,120)+Convert(Varchar(5),AOnDuty,108)ASDateTime)EndAS'AOnDuty'
,CaseWhenLeft(FristBrushDate,1)='0'ANDConvert(varchar(10),AOnDuty,120)<Convert(varchar(10),AOffDuty,120)ThenCAST(Convert(Varchar(11),Dateadd(dd,1,OnDutyDate),120)+Convert(Varchar(5),AOffDuty,108)ASDateTime)ELSECAST(Convert(Varchar(11),OnDutyDate,120)+Convert(Varchar(5),AOffDuty,108)ASDateTime)EndAS'AOffDuty'
,CAST(Convert(Varchar(11),OnDutyDate,120)+Convert(Varchar(5),BOnDuty,108)ASDateTime)AS'BOnDuty'
,CAST(Convert(Varchar(11),OnDutyDate,120)+Convert(Varchar(5),BOffDuty,108)ASDateTime)AS'BOffDuty'
,CAST(Convert(Varchar(11),OnDutyDate,120)+Convert(Varchar(5),COnDuty,108)ASDateTime)AS'COnDuty'
,CAST(Convert(Varchar(11),OnDutyDate,120)+Convert(Varchar(5),COffDuty,108)ASDateTime)AS'COffDuty'
From
.DepartmentCode=d.DepartmentCode
.Employeeid=a.Employeeid
INNERJOINAttendanceSpellpona.Employeeid=p.Employeeidanda.WorkOndate=p.OnDutyDate
LEFTJOINAttendanceShiftssonp.Shiftid=s.Shiftid
)tb1
)tb2WhereError=1

UNIONALL

Select
Number
,ChineseName
,DepartmentCode
,DepartmentName
,ShiftId
,ShiftName
,Degree
,AskForLeaveType
,WorkOnDate
,CaseWhenRight(Convert(Varchar(10),WorkOnDate,120),5)IN(selectRight(Convert(Varchar(10),HolidayDate,120),5)fromAttendanceHoliday)THEN'2-公众假上班'ELSE'0-平时上班'ENDAS'OnDutyType'
,StartTime
,EndTime
,AOnDuty
,AOffDuty
,Allday
,SumTotal
,Error
From
(
Select
Number
,ChineseName
,d.DepartmentCode
,DepartmentName
,p.ShiftId
,p.ShiftName
,Degree
,AskForLeaveType
,WorkOnDate
,StartTime
,EndTime
,Sumtotal
,NULLAS'AOnDuty'
,NULLAS'AOffDuty'
,AllDay
,1AS'Error'
From
AttendanceAskForLeavea
LEFTJOINEmployeeseONa.Employeeid=e.Employeeid
LEFTJOINDepartmentsdONe.DepartmentCode=d.DepartmentCode
LEFTJOINAttendanceSpellpONa.Employeeid=p.EmployeeidANDa.WorkOnDate=p.OnDutyDate
LEFTJOINAttendanceShiftssONp.ShiftId=s.ShiftId
Where
Left(IncumbencyStatus,1)<>1
Groupby
Number,ChineseName,d.DepartmentCode,DepartmentName,p.ShiftId,p.ShiftName,Degree,AskForLeaveType,AllDay,WorkOnDate,StartTime,EndTime,Sumtotal
having
Count(1)>1
)tb3
)tb4

对你的代码格式化后发现,还缺少一些语句,你是否粘贴完整了?

读完SQL语句后发现,其实是一个考勤核算的查询语句,是两个大的SQL查询Union ALL的结果