select CASE WHEN left(StartLocation,2)in('WM','BM') THEN 'BWM' ELSE left(StartLocation,2) END s,CONVERT(NVARCHAR(10),ReqTime) as dt,ReqTime,CONVERT(NVARCHAR(10),EndTime) as tt,DATEDIFF(ss,ReqTime,EndTime) as gsfrom dbo.testwhere ReqTime is not nulland EndTime is not nulland between '2023-02-14' and '2023-02-17 'and SUBSTRING(ReqTime,12,2)>='20'and SUBSTRING(ReqTime,12,2)<'24'and left(StartLocation,2) !='XS'union allselect CASE WHEN left(StartLocation,2)in('WM','BM') THEN 'BWM' ELSE left(StartLocation,2) END s,CONVERT(NVARCHAR(10),ReqTime) as dt,ReqTime,CONVERT(NVARCHAR(10),EndTime) as tt,DATEDIFF(ss,ReqTime,EndTime) as gsfrom dbo.testwhere ReqTime is not nulland EndTime is not nulland between '2023-02-15' and '2023-02-18 'and SUBSTRING(ReqTime,12,2)>='00'and SUBSTRING(ReqTime,12,2)<'08'and left(StartLocation,2) !='XS'查出的数据分别是14号20点到24点的数据,15号0点到8点的数据和20点到24点的数据,16号0点到8点的数据和20点到24点的数据,和17号0点到8点的数据,希望得到的结果是将每天晚八的数据和第二天早八的数据放在一起,求其gs字段的和,十四号的晚八到十五号早八的gs的和,十五号晚八到十六号早八的gs的和,十六号晚八到十七号早八的gs的和,共分为三组数据,分组后的数据不需要ReqTime字段的数据,只需要s、每组和sum(gs)的数据数据如下:sdtReqTimettgsSM2023/2/142023/2/14 21:1302 14 2023127SM2023/2/142023/2/14 21:1502 14 2023109SM2023/2/142023/2/14 21:1602 14 202394SM2023/2/152023/2/15 1:0802 15 2023159SM2023/2/152023/2/15 1:1002 15 2023117SM2023/2/152023/2/15 1:1102 15 202394SM2023/2/152023/2/15 22:3602 15 2023126SM2023/2/152023/2/15 22:3802 15 2023164SM2023/2/152023/2/15 22:4202 15 2023158SM2023/2/162023/2/16 3:2702 16 2023294SM2023/2/162023/2/16 3:3102 16 2023131SM2023/2/162023/2/16 3:3202 16 2023169SM2023/2/162023/2/16 23:1102 16 2023159SM2023/2/162023/2/16 23:1502 16 202388SM2023/2/162023/2/16 23:1602 16 2023112SM2023/2/172023/2/17 3:2202 17 2023130SM2023/2/172023/2/17 3:2502 17 2023143SM2023/2/172023/2/17 3:2602 17 2023160