0

こんにちは、私はこれに問題があります:

Select Customer_Tool_Lookup.ID, 
    Customer.CustomerName, 
    (select count(ID) as perDay 
    FROM CustomerData 
    WHERE DatetimeInserted >= '2013-04-29 00:00:00.000' 
        AND DatetimeInserted <= '2013-04-29 11:59:59.599' 
        AND Customer_ID = Customer_Tool_Lookup.Customer_ID) as DCount,
    (select count(ID) as perMonth 
    FROM CustomerData 
    WHERE DatetimeInserted >= '2013-04-01 00:00:00.000' 
        AND DatetimeInserted <= '2013-04-30 11:59:59.599' 
        AND Customer_ID = Customer_Tool_Lookup.Customer_ID) as mCount,
    (select count(ID) as perYear 
    FROM CustomerData 
    WHERE DatetimeInserted >= '2013-01-01 00:00:00.000' 
        AND DatetimeInserted <= '2013-04-30 11:59:59.599' 
        AND Customer_ID = Customer_Tool_Lookup.Customer_ID) as yCount,
    Customer_tool_Lookup.PricePerClick, 
    Customer_Tool_lookup.MinimumPerMonth, 
    case 
        when ClicksPerMonth > (select count(ID) as perMonth 
                                FROM CustomerData 
                                WHERE DatetimeInserted >= '2013-04-01 00:00:00.000' 
                                    AND DatetimeInserted <= '2013-04-30 11:59:59.599' 
                                    AND Customer_ID = Customer_Tool_Lookup.Customer_ID) 
        then ClicksPerMonth 
        else ((select count(ID) as perMonth 
                FROM CustomerData 
                WHERE DatetimeInserted >= '2013-04-01 00:00:00.000' 
                    AND DatetimeInserted <= '2013-04-30 11:59:59.599' 
                    AND Customer_ID = Customer_Tool_Lookup.Customer_ID) - Customer_tool_lookup.MinimumPerMonth) * PricePerClick END as TDMonth
FROM Customer_tool_Lookup Left join Customer on Customer.ID = Customer_Tool_Lookup.Customer_ID 

エラーが発生します:

objectName 'Customer_tool_Lookup' が無効です

andサブクエリの最後に次のステートメントを追加したときに始まりました。

AND Customer_ID = Customer_Tool_Lookup.Customer_ID <--

それらのそれぞれ 1 つ。

私は通常、以前にサブクエリを実行したことがある SQL の質問をしませんが、何らかの理由で親データの使用に問題があります。

ありがとう!

4

1 に答える 1