Update和Select结合统计更新
2024-08-27 12:18:27
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
最新文章
- 关于java中接口定义常量和类定义常量的区别
- 07_编写天气预报和手机归属地的WebService
- easyui加载datagrid时随着窗体大小改变而改变
- 名词释义(ActiveMQ 和 Webservice)
- ERP开发分享 1 数据库表设计
- 怎么书写高质量jQuery代码
- 检测 NSObject 对象持有的强指针
- Cocos2d-x win7下 android环境搭建
- 20个命令行工具监控 Linux 系统性能(转载)
- Xming + PuTTY 在Windows下远程Linux主机
- TEX Quotes(字符串,水)
- mysql基础入门
- Windows 事件查看器(收集)
- 【转】使用sinopia五步快速完成本地npm搭建
- 移动端click延迟和tap事件
- Redis连接方式
- nodejs部署智能合约的方法-web3 0.20版本
- linux c 编程 ------ 头文件及其作用
- Oracle 闪回
- BSGS算法及其扩展
热门文章
- Linux02 cd命令以及绝对路径和相对路径
- Python中遍历整个列表及注意点(参考书籍Python编程从入门到实践)
- 安利一下stringstream
- hdu 1501 贪心问题
- Python之(scikit-learn)机器学习
- .net SHA-256 SHA-1
- Centos6 Connect WiFi
- VS2017 CMD多出 “进程 6420)已退出,返回代码为: 0”的内容
- iOS - Objective-C 关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- shopxo代码审计