如何在结果中获得null segmentid? [英] How to get the null segmentid in the result?
问题描述
我正在尝试将列值设为null但我无法这样做。
我尝试了什么:
我有以下查询,它给出了所有结果,包括Null。但我需要根据注释的segmentID进行过滤,我也需要null值。不需要除以下区段以外的区段(当前评论)
I am trying to get the column value that is null but i am not able to do so.
What I have tried:
I have below query and it is giving all results including Null as well. But i need to filter on the basis of commented segmentIDs and i need null value as well. Don't require the Segments else than below filter(Commented Currently)
Select distinct SegmentID,Sum(distance) as TotalDistance from [dbo].[tblBookingContent]
where Orgnization = 'REGERINGSKANSLIET' --and segmentid in ('LUX001S02','LUX001S11','SWE001S03','SWE001S09','SWE001S14','SWE001S20','SWE001S15','SWE001S23')
and IsV4 in (0,1)
and departuredate between
convert(datetime, '2016-07-01', 110) and
convert(datetime, '2016-09-30', 110) and MPSS= 1
and BookingNumber not in (select BookingNumber from tblBookingContent where BookingStatus=1)
group by SegmentId
SegmentID |距离
========== | =========
NULL | 28088.9700
SWE001S02 | 125.0990
SWE001S03 | 9295.0810
SWE001S06 | 710.4410
SWE001S09 | 15510.0310
SWE001S11 | 733.4110
预期结果
===============
SegmentID |距离
========== | =========
NULL | 28088.9700
SWE001S03 | 9295.0810
SWE001S09 | 15510.0310
SegmentID | Distance
========== | =========
NULL | 28088.9700
SWE001S02 | 125.0990
SWE001S03 | 9295.0810
SWE001S06 | 710.4410
SWE001S09 | 15510.0310
SWE001S11 | 733.4110
Expected Result
===============
SegmentID | Distance
========== | =========
NULL | 28088.9700
SWE001S03 | 9295.0810
SWE001S09 | 15510.0310
推荐答案
看起来很简单,我不太明白weel但是试试这个:
It seems easy, I'm not sure to understand weel but try this:
Select distinct SegmentID,Sum(distance) as TotalDistance from [dbo].[tblBookingContent]
where Orgnization = 'REGERINGSKANSLIET'
and (segmentid is null or segmentid in ('LUX001S02','LUX001S11','SWE001S03','SWE001S09','SWE001S14','SWE001S20','SWE001S15','SWE001S23'))
and IsV4 in (0,1)
and departuredate between
convert(datetime, '2016-07-01', 110) and
convert(datetime, '2016-09-30', 110) and MPSS= 1
and BookingNumber not in (select BookingNumber from tblBookingContent where BookingStatus=1)
group by SegmentId
这篇关于如何在结果中获得null segmentid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!