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.Code
left 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.CourseSubjectId
left join FM_StudentContact cc on cc.StudentId=stu.Id
left join FM_SchoolArea scl on scl.Id=stu.SchoolAreaId left join FM_StudentVisitRecord svr on svr.Id=
(select top 1 svr1.Id from FM_Student stu1
join 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.FollowUserID
left join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatus where 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 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)) as ArrearageAmount --欠费金额 from FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Code
left 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.CourseSubjectId
left join FM_StudentContact cc on cc.StudentId=stu.Id
left join FM_SchoolArea scl on scl.Id=stu.SchoolAreaId left join FM_StudentVisitRecord svr on svr.Id=
(select top 1 svr1.Id from FM_Student stu1
join 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.FollowUserID
left join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatus where 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)

最新文章

  1. rbd命令
  2. Python开发【第三章】:Python函数介绍
  3. ubuntu 14.04 https 形式安装docker 私有库 harbor
  4. js回调函数(callback)理解
  5. virtualBox虚拟机安装与主机互访和实现上网配置
  6. longene QQ 安装目录
  7. FTPClient文件下载
  8. CSS flex 布局 一些基本属性应用
  9. 大话Python格式化输出字符串
  10. 基于vue,打印机打印暂且处理
  11. C++堆栈详解
  12. [SDOI2014]重建
  13. flink如何动态支持依赖jar包提交
  14. 控制结构(8): 线性化(linearization)
  15. java树形菜单实现
  16. Django-models &amp; QuerySet API
  17. keras常见参数input_dim、input_length理解
  18. Linux学习笔记:Jenkins安装
  19. lower_case_table_names
  20. Python中的类(下)

热门文章

  1. 前沿技术解密——VirtualDOM
  2. 网页内容导出word/excel的js代码
  3. 调用axis2开发的接口遇到的问题
  4. 可能 delphi7 下稳定的最后一版本 GDIPLUS
  5. 菜鸟教程之工具使用(十二)——Eclipse突出显示选中的相同变量
  6. SAP S4 Finance6个支持企业实时财务管理的主要创新领域
  7. C# 调用百度地图Web服务API
  8. FileZilla FTP Server 高级防火墙例外
  9. POJ 1013 Counterfeit Dollar
  10. Probabilistic Graphical Models