0

我如何返回一个月没有销售的记录,例如 2004 年 7 月?

用户将提供一个日期,比如 2004 年 7 月,然后我需要查看没有销售的产品。

SELECT 

 DP.ProductID
,DP.Name
,FS.OrderDate
,FS.OrderQty
,FS.OrderAmount

FROM dbo.DimProduct AS DP

LEFT JOIN dbo.FactSales as FS on FS.ProductID = DP.ProductID
4

3 回答 3

1
SELECT  DP.*
FROM    dbo.DimProduct AS DP
        LEFT JOIN dbo.FactSales as FS 
            ON  FS.ProductID = DP.ProductID AND
                DATENAME(month, FS.OrderDate) = 'July' AND
                YEAR(FS.OrderDate) = 2004
WHERE   FS.ProductID IS NULL
于 2013-05-31T14:03:19.287 回答
0

也许这可以解决您的问题:

SELECT 

 DP.ProductID
,DP.Name
,FS.OrderDate
,FS.OrderQty
,FS.OrderAmount

FROM dbo.DimProduct AS DP
LEFT JOIN dbo.FactSales as FS on FS.ProductID = DP.ProductID 

WHERE FS.OrderAmount == 0
于 2013-05-31T14:06:25.777 回答
0
SELECT  DP.*
FROM    dbo.DimProduct AS DP
WHERE   NOT EXISTS ( SELECT 1
                     FROM   dbo.FactSales AS FS
                     WHERE  FS.ProductID = DP.ProductID
                            AND DATENAME(month, FS.OrderDate) = 'July'
                            AND YEAR(FS.OrderDate) = 2004 )
于 2013-05-31T14:23:06.710 回答