开发者

Query won't show decimal values

I have an Access query that should pull the quantity purchased in a month for a set of items. My join is set to select all items from Analysis, and items from product that match analysis.

    SELECT AnalysisItems.Pmid, AnalysisItems.ProductName, Sum(Transactions.TransactionQty) 
    AS SumOfTransactionQty, Transactions.StoreAccount
    FROM AnalysisItems INNER JOIN Transactions ON AnalysisItems.开发者_高级运维Pmid = Transactions.Pmid
    WHERE (((Transactions.TransactionDate) Between #4/1/2011# And #4/30/2011#) 
    AND StoreAccount = 964290)
    GROUP BY AnalysisItems.Pmid, AnalysisItems.ProductName, Transactions.StoreAccount
    ORDER BY AnalysisItems.ProductName;

I want to see all 78 analysis items, whether they have a quantity value or not. This only returns items that have quantities. It also does not return values that are negative or values between 0 and 1 ... it won't show me 0.50 even though I know there are some decimal values in there. Everything is set to Standard decimal, scale 2

I've tried changing to general number and getting rid of the format completely but that doesn't work either.

So my questions are: What can I try to see the decimal values in my query, and how can I see all the items?


You have a part of your query as:

FROM AnalysisItems INNER JOIN Transactions ON AnalysisItems.Pmid = Transactions.Pmid
WHERE (((Transactions.TransactionDate) Between #4/1/2011# And #4/30/2011#) 

The inner join that you have specified, does not give the results that you asked for - ideally, you want to use a left join for your purpose. Replace

FROM AnalysisItems INNER JOIN Transactions

with

FROM AnalysisItems LEFT JOIN Transactions

I think it should work fine


"I want to see all 78 analysis items, whether they have a quantity value or not."

If that means you want AnalysisItems rows included in the result set even if those items don't have any matches in Transactions for the month of April and StoreAccount 964290, they will not be included when you place those conditions in the WHERE clause ... you'll only get the rows which match the WHERE clause conditions.

I think you need to use a subquery for Transactions and move the WHERE clause into the subquery. And LEFT JOIN AnalysisItems to the subquery.

SELECT
    a.Pmid,
    a.ProductName,
    Sum(t.TransactionQty) AS SumOfTransactionQty,
    t.StoreAccount
FROM
    AnalysisItems AS a
    LEFT JOIN [
        SELECT
            Pmid,
            TransactionQty,
            StoreAccount
        FROM Transactions
        WHERE
            (TransactionDate Between #4/1/2011# And #4/30/2011#) 
            AND StoreAccount = 964290
        ]. AS t
        ON a.Pmid = t.Pmid
GROUP BY
    a.Pmid, 
    a.ProductName,
    t.StoreAccount
ORDER BY
    a.ProductName;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜