码迷,mamicode.com
首页 > 其他好文 > 详细

第一次用临时表的感受:

时间:2019-10-08 16:12:38      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:font   receive   where   com   ddc   null   count   临时表   and   

WITH 
WOTotal AS
(
 SELECT sysuser.REALNAME,count(1) AS TotalCount FROM WO_OperaionWorkOrderBills owobill WITH(nolock)
 LEFT JOIN SYS_USER sysuser WITH(NOLOCK) ON sysuser.USERID=owobill.OWOReceiver 
 WHERE sysuser.REALNAME IS NOT NULL  and OWOState!=OWO_Completed
 GROUP BY sysuser.REALNAME
),
WOAdd AS
(
SELECT sysuser.REALNAME,count(1) AS AddCount  FROM WO_OperaionWorkOrderBills owobill WITH(nolock)
 LEFT JOIN SYS_USER sysuser WITH(NOLOCK) ON sysuser.USERID=owobill.OWOReceiver 
 WHERE sysuser.REALNAME IS NOT NULL and OWOState=OWO_Add
 GROUP BY sysuser.REALNAME
),
WODispatched AS
(
SELECT sysuser.REALNAME,count(1) AS DispatchedCount  FROM WO_OperaionWorkOrderBills owobill WITH(nolock)
 LEFT JOIN SYS_USER sysuser WITH(NOLOCK) ON sysuser.USERID=owobill.OWOReceiver 
 WHERE sysuser.REALNAME IS NOT NULL and OWOState=OWO_Dispatched
 GROUP BY sysuser.REALNAME
)
SELECT TOP 10 1 as time_sec, WOTotal.RealName as metric ,TotalCount as value,isnull(AddCount,0) AS 新建,isnull(DispatchedCount,0) 派单
 FROM WOTotal 
 LEFT JOIN WOAdd ON WOTotal.RealName=WOAdd.RealName
 LEFT JOIN WODispatched ON WOTotal.RealName=WODispatched.RealName 

ORDER BY TotalCount desc

 

第一次用临时表的感受:

标签:font   receive   where   com   ddc   null   count   临时表   and   

原文地址:https://www.cnblogs.com/gao109214/p/11635712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!