从条件聚合结果中删除 NULLS
Removing NULLS from conditional aggregation results
我很难删除 NULLS。 ISNULL 语句似乎适用于动态结果,但不适用于第二个结果。
我的最终提取查询是:
select itemid,title,description,cat,fibre,washing,colours,promo,
max(case when seqnum = 1 then isnull(chm_sizegrouping,'') end) as sizes_1,
max(case when seqnum = 2 then isnull(chm_sizegrouping,'') end) as sizes_2,
max(case when seqnum = 3 then chm_sizegrouping end) as sizes_3,
max(case when seqnum = 4 then chm_sizegrouping end) as sizes_4)
显示的结果是:
itemid sizes_1 sizes_2
LM008 one NULL
LM009 NULL
LM010 NULL
lm011 NULL
非常感谢任何帮助,
谢谢。
不幸的是,您必须对每个可以检索 NULL
值的字段使用 ISNULL
函数。
试试这个:
select itemid,title,description,cat,fibre,washing,colours,promo,
isnull(max(case when seqnum = 1 then chm_sizegrouping end),'') as sizes_1,
isnull(max(case when seqnum = 2 then chm_sizegrouping end),'') as sizes_2,
........
只需将 ISNULL
检查放在 MAX()
函数的外部,如下所示:
select itemid,title,description,cat,fibre,washing,colours,promo,
isnull(max(case when seqnum = 1 then chm_sizegrouping end), '') as sizes_1,
isnull(max(case when seqnum = 2 then chm_sizegrouping end),'') as sizes_2,
max(case when seqnum = 3 then chm_sizegrouping end) as sizes_3,
max(case when seqnum = 4 then chm_sizegrouping end) as sizes_4)
我很难删除 NULLS。 ISNULL 语句似乎适用于动态结果,但不适用于第二个结果。
我的最终提取查询是:
select itemid,title,description,cat,fibre,washing,colours,promo,
max(case when seqnum = 1 then isnull(chm_sizegrouping,'') end) as sizes_1,
max(case when seqnum = 2 then isnull(chm_sizegrouping,'') end) as sizes_2,
max(case when seqnum = 3 then chm_sizegrouping end) as sizes_3,
max(case when seqnum = 4 then chm_sizegrouping end) as sizes_4)
显示的结果是:
itemid sizes_1 sizes_2
LM008 one NULL
LM009 NULL
LM010 NULL
lm011 NULL
非常感谢任何帮助,
谢谢。
不幸的是,您必须对每个可以检索 NULL
值的字段使用 ISNULL
函数。
试试这个:
select itemid,title,description,cat,fibre,washing,colours,promo,
isnull(max(case when seqnum = 1 then chm_sizegrouping end),'') as sizes_1,
isnull(max(case when seqnum = 2 then chm_sizegrouping end),'') as sizes_2,
........
只需将 ISNULL
检查放在 MAX()
函数的外部,如下所示:
select itemid,title,description,cat,fibre,washing,colours,promo,
isnull(max(case when seqnum = 1 then chm_sizegrouping end), '') as sizes_1,
isnull(max(case when seqnum = 2 then chm_sizegrouping end),'') as sizes_2,
max(case when seqnum = 3 then chm_sizegrouping end) as sizes_3,
max(case when seqnum = 4 then chm_sizegrouping end) as sizes_4)