我想知道是否可以在另一个临时表中创建临时表,然后从外部嵌套表中运行查询。
我对2个已连接的表进行查询,这些表生成了一次在多个仓库中分配库存的销售订单列表。 (第一个临时表)。我现在需要使用此列表作为临时表来查询原始原始数据表之一,以仅收集列出的销售订单的数据。
答案 0 :(得分:2)
在他的一条评论中提供了@ HABO的链接,我已经解决了这个问题。以下是我的决议
WITH salesorderwhlist
AS (SELECT DISTINCT sordetail.salesorder,
sordetail.mwarehouse AS Warehouse
FROM sordetail
INNER JOIN sormaster
ON sordetail.salesorder = sormaster.salesorder
WHERE ( sordetail.linetype NOT IN ( '4', '5', '6', '7' ) )
AND ( sordetail.mshipqty <> 0 )
AND ( sormaster.orderstatus NOT IN ( '8', '9', 'S', '\', '*' ) )
),
filteredlist
AS (SELECT salesorder,
Count(salesorder) AS WhCount
FROM salesorderwhlist AS SOWL
GROUP BY salesorder
HAVING Count(salesorder) > 1)
SELECT sordetail.*
FROM sordetail
RIGHT JOIN filteredlist
ON sordetail.salesorder = filteredlist.salesorder
感谢HABO的意见。