我的查询存在以下问题。
我正在尝试将多个表(Fact_Contact,Quali_Seg等)中的数据导入到一个表(Fact_Forecast)中。这是为了预测有多少人有资格获得特定优惠。我遇到的问题是,由于某种原因,导入时从Fact_Contact中提取的列Date_ID具有NULL值。我不知道这些NULL值来自何处,因为表Fact_Contact在DATE_ID列中没有任何NULL值。
这是有问题的查询部分,
DECLARE @lastDateID int
SELECT TOP 1 @lastDateID = date_id
FROM Fact_Contact
ORDER BY CREATE_DATE DESC
SELECT date_id, Offers.Segmentation_id, Offers.Offer_Code, Offers.Wave_no,
Offers.cadencevalue,
CASE
WHEN dailydata.activity_count IS NOT NULL THEN dailydata.activity_count
ELSE 0
END as "activity_count"
FROM (
SELECT s.Segmentation_id, s.Offer_Code, s.Wave_no, o.cadencevalue,
o.campaign_id, o.offer_desc
FROM Forecast_Model.dbo.Quali_Segment s
LEFT JOIN Forecast_Model.dbo.Dim_Offers o
ON s.offer_code = o.offer_code
) Offers
LEFT JOIN (
SELECT date_id, Offer_Code_1 Offer_Code,
segmentation_group_id, Count(indv_role_id) Activity_count
FROM Forecast_Model.dbo.Fact_Contact
WHERE date_id = @lastDateID
GROUP BY offer_code_1,segmentation_group_id,date_id
) DailyData
ON DailyData.offer_code = Offers.offer_code
AND Offers.Segmentation_id = dailydata.segmentation_group_id
ORDER BY Segmentation_id,Wave_no
我提到的Date_ID列只有2个日期与@LastDateID相同,即2014-05-20,但其余的都是NULL。
谢谢你, 奥马
答案 0 :(得分:1)
date_id将为NULL