博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL Server case when 日期字符串转换 多表查询 嵌套子查询
阅读量:7116 次
发布时间:2019-06-28

本文共 3512 字,大约阅读时间需要 11 分钟。

select distinct stu.*, dbo.GetClassNameByStudentCode(stu.Code) as ClassName,dbo.GetCourseNameByStudentCode(stu.Code) as CourseName,dbo.GetLinkmanByStudentId(stu.Id) as Linkman,dbo.GetContactByStudentId(stu.Id) as Contact, case when svr.Linkman is not NULL then svr.Linkman else dbo.GetLinkmanByStudentId(stu.Id) end as VisitLinkman,case when svr.Contact is not NULL then svr.Contact else dbo.GetContactByStudentId(stu.Id) end as VisitContact,case when u1.Sname is not NULL and u1.Sname<>'' then u1.Sname else u1.Username end as VisitFollowUserName, CONVERT(CHAR(10), svr.FollowTime, 23) as VisitLastFollowTime, scl.Name as SchoolAreaName, svr.ContentMemo as VisitContentMemo, dict1.Name as StudentStatusName from FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Codeleft join FM_Class cls on cls.ClassCode=sc.ClassCode left join FM_Course cou on cou.Id=cls.CourseId left join FM_CourseSubject cs on cs.Id=cou.CourseSubjectIdleft join FM_StudentContact cc on cc.StudentId=stu.Idleft join FM_SchoolArea scl on scl.Id=stu.SchoolAreaIdleft join FM_StudentVisitRecord svr on svr.Id=(select top 1 svr1.Id from FM_Student stu1join FM_StudentVisitRecord svr1 on stu1.Code=svr1.Code and stu1.Id=stu.Id order by svr1.Id desc)left join Sys_User u1 on u1.Id=svr.FollowUserIDleft join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatuswhere stu.DelFlg<>{
0}

 

select distinct stu.*,scl.Name as SchoolAreaName,dbo.GetClassNameByStudentCode(stu.Code) as ClassName,dbo.GetCourseNameByStudentCode(stu.Code) as CourseName,dbo.GetLinkmanByStudentId(stu.Id) as Linkman,dbo.GetContactByStudentId(stu.Id) as Contact,case when svr.Linkman is not NULL then svr.Linkman else dbo.GetLinkmanByStudentId(stu.Id) end as VisitLinkman,case when svr.Contact is not NULL then svr.Contact else dbo.GetContactByStudentId(stu.Id) end as VisitContact,svr.ContentMemo as VisitContentMemo,case when u1.Sname is not NULL and u1.Sname<>'' then u1.Sname else u1.Username end as VisitFollowUserName,CONVERT(CHAR(10), svr.FollowTime, 23) as VisitLastFollowTime,dict1.Name as StudentStatusName,((select sum(pf.PayAmount) from FM_PayFlow pfjoin FM_Student stu1 on pf.CustomerCode=stu1.Code and stu1.Code=stu.Code) -(select sum(psf.PayAmount) from FM_PayStepFlow psf join FM_PayFlow pf1 on psf.PayFlowId=pf1.Idjoin FM_Student stu1 on pf1.CustomerCode=stu1.Code and stu1.Code=stu.Code))  as ArrearageAmount --欠费金额from FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Codeleft join FM_Class cls on cls.ClassCode=sc.ClassCode left join FM_Course cou on cou.Id=cls.CourseId left join FM_CourseSubject cs on cs.Id=cou.CourseSubjectIdleft join FM_StudentContact cc on cc.StudentId=stu.Idleft join FM_SchoolArea scl on scl.Id=stu.SchoolAreaIdleft join FM_StudentVisitRecord svr on svr.Id=(select top 1 svr1.Id from FM_Student stu1join FM_StudentVisitRecord svr1 on stu1.Code=svr1.Code and stu1.Id=stu.Id order by svr1.Id desc)left join Sys_User u1 on u1.Id=svr.FollowUserIDleft join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatuswhere stu.DelFlg<>{
0} and (sc.Status='{2}' or sc.Status is NULL and (select sum(pf.PayAmount) from FM_PayFlow pf join FM_Student stu1 on pf.CustomerCode=stu1.Code and stu1.Code=stu.Code) > (select sum(psf.PayAmount) from FM_PayStepFlow psf join FM_PayFlow pf1 on psf.PayFlowId=pf1.Id join FM_Student stu1 on pf1.CustomerCode=stu1.Code and stu1.Code=stu.Code)

 

转载于:https://www.cnblogs.com/s0611163/p/3748151.html

你可能感兴趣的文章
码农张的Bug人生 - 见面之礼
查看>>
JS异步编程之Promise
查看>>
【算法专栏】-- 谈谈时间复杂度
查看>>
元数据治理框架Atlas研究——JanusGraph图数据库对象关系映射
查看>>
力扣(LeetCode)155
查看>>
sas 做 titanic 未完待续
查看>>
区块链是一个公共数据库,要放在一个块内
查看>>
jqGrid的rowNum属性默认值、-1情况的介绍
查看>>
一步步学会用docker部署应用(nodejs版)
查看>>
分享10个免费H5模版(主题)资源网站
查看>>
RabbitMQ预研
查看>>
机器学习之分类结果的评价
查看>>
理解五个基本概念,让你更像机器学习专家
查看>>
你应该知道的数据库数据类型及其设计原则
查看>>
解决vue报错Failed to mount component
查看>>
[LeetCode] 124. Binary Tree Maximum Path Sum
查看>>
活学活用! 用Local Storage实现多人聊天室
查看>>
一次爬虫实践记录
查看>>
炫酷粒子表白,双十一脱单靠它了!
查看>>
mysql锁以及实践总结
查看>>