第一次用临时表的感受:

Posted gao109214

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一次用临时表的感受:相关的知识,希望对你有一定的参考价值。

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

 

以上是关于第一次用临时表的感受:的主要内容,如果未能解决你的问题,请参考以下文章

Oracle临时表(Temporary Table)

Oracle临时表(Temporary Table)

关于mysql建立临时表的问题(新手入门)

sql server创建临时表的两种写法和删除临时表

MYSQL存储引擎InnoDB(三十五):临时表空间

mysql 临时表的建立和用途