Update和Select结合统计更新

update table_a set updatetime=getdate(), name=b.name

from (select name,age from table_b where table_b.Id=1) as b

where table_a.id=1

--

UPDATE A SET A1 = B1, A2 = B2, A3 = B3 FROM A, B WHERE A.ID = B.ID
update Table_Main set DataStatusId='902e0650-4fd2-432b-ad56-0750ba81f71e',
MonthClassHourSum=tmain.MonthClassHourSum,FTCNClassHourSum=tmain.FTCNClassHourSum,PTCNClassHourSum=tmain.PTCNClassHourSum,
FTENClassHourSum=tmain.FTENClassHourSum,PTENClassHourSum=tmain.PTENClassHourSum,
StaffClassHourSum=tmain.StaffClassHourSum, TakeClassHourSum=tmain.TakeClassHourSum,
TeachingTotalSum=tmain.TeachingTotalSum, TeachingClassSum=tmain.TeachingClassSum,
TeachingStudentSum=tmain.TeachingStudentSum, StudentLearnAge=tmain.StudentLearnAge,
TeachingPercent=tmain.TeachingPercent,TotalAttendStudentCnt=tmain.TeachingStudentSum, TotalClassTeacherCount=tmain.TotalClassTeacherCount,
TotalTeacherCount=tmain.TotalTeacherCount, GroupTeachItemCourse=tmain.GroupTeachItemCourse
from
(select sum(TeacherClassHour)as 'MonthClassHourSum',
sum(Case when TeacherTypeId='t1' then TeacherClassHour else 0 end) as 'FTCNClassHourSum',
sum(Case when TeacherTypeId='t2' then TeacherClassHour else 0 end) as 'PTCNClassHourSum',
sum(Case when TeacherTypeId='t3' then TeacherClassHour else 0 end) as 'FTENClassHourSum',
sum(Case when TeacherTypeId='t4' then TeacherClassHour else 0 end) as 'PTENClassHourSum',
sum(Case when TeacherTypeId='t5' then TeacherClassHour else 0 end) as 'StaffClassHourSum',
sum(Case when TeacherTypeId='t6' then TeacherClassHour else 0 end) as 'TakeClassHourSum',
COUNT(DISTINCT Id) as 'TeachingTotalSum',COUNT(DISTINCT TeachItemClassId) as 'TeachingClassSum',sum(AttendStudentCnt) as 'TeachingStudentSum',
Convert(decimal(18,2),sum(TeacherClassHour)/COUNT(DISTINCT TeacherUserID)) as 'StudentLearnAge',
100*Convert(decimal(18,2),COUNT(DISTINCT TeacherUserID)/(select count(DISTINCT IdCard) from Table_User)) as 'TeachingPercent',
COUNT(DISTINCT TeacherUserID) as 'TotalClassTeacherCount',(select count(DISTINCT IdCard) from Table_User) as 'TotalTeacherCount',
(select count(DISTINCT Id) from [dbo].[Table_Group] where FKMainId=@mainId) as 'GroupTeachItemCourse'
from [dbo].[Table_Detail] where FKTMainId=@mainId
) tmain
where Tabel_Main.Id=@mainId

SQL

最新文章

  1. 关于java中接口定义常量和类定义常量的区别
  2. 07_编写天气预报和手机归属地的WebService
  3. easyui加载datagrid时随着窗体大小改变而改变
  4. 名词释义(ActiveMQ 和 Webservice)
  5. ERP开发分享 1 数据库表设计
  6. 怎么书写高质量jQuery代码
  7. 检测 NSObject 对象持有的强指针
  8. Cocos2d-x win7下 android环境搭建
  9. 20个命令行工具监控 Linux 系统性能(转载)
  10. Xming + PuTTY 在Windows下远程Linux主机
  11. TEX Quotes(字符串,水)
  12. mysql基础入门
  13. Windows 事件查看器(收集)
  14. 【转】使用sinopia五步快速完成本地npm搭建
  15. 移动端click延迟和tap事件
  16. Redis连接方式
  17. nodejs部署智能合约的方法-web3 0.20版本
  18. linux c 编程 ------ 头文件及其作用
  19. Oracle 闪回
  20. BSGS算法及其扩展

热门文章

  1. Linux02 cd命令以及绝对路径和相对路径
  2. Python中遍历整个列表及注意点(参考书籍Python编程从入门到实践)
  3. 安利一下stringstream
  4. hdu 1501 贪心问题
  5. Python之(scikit-learn)机器学习
  6. .net SHA-256 SHA-1
  7. Centos6 Connect WiFi
  8. VS2017 CMD多出 “进程 6420)已退出,返回代码为: 0”的内容
  9. iOS - Objective-C 关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
  10. shopxo代码审计