0
我有這個疑問:兩列的按ID和日期分組,但每個組的日期?
declare @values table
(
Id int,
Dept varchar(1),
CounterL int,
CounterU int,
InsertDate datetime
)
insert into @values
select 1, 'L', 5, null, '2017-10-28 4:00:00.000'
union
select 1, 'L', 8, null, '2017-10-28 4:00:00.000'
union
select 1, 'U', null, 30, '2017-10-28 3:00:00.000'
union
select 1, 'U', null, 40, '2017-10-28 3:00:00.000'
select id, sum(counterl), sum(counteru) from @values
where (datepart(hh, insertdate) = 4 or datepart(hh, insertdate) = 3)
group by id, cast(InsertDate as date)
下收益的總和,但我希望能夠包括這些分組的日期。
的例子會是這個樣子:
id ColumnL, ColumnU, Date ValueU ValueL
1 13 70 2017-10-28 '2017-10-28 3:00:00.000' '2017-10-28 4:00:00.000'
總會有一天兩個小時,無論是HR 3或4
感謝。
我有,但我需要知道valueU(70)具有「2017年10月28日3:00:00.000',而L值(13)爲'2017-10-28 4:00:00.000'。我在問題中包含了所需的結果集 – rbhat