There is no way in the ANSI SQL standard statement to do what you are looking for. what was said above about the stored procedure or the use of cursors can be done, but you can also write instructions in T-SQL or PL / SQL using cursors to determine the amount of each of the origin and time of the start of the reference - something like this in T-SQL (Microsoft SQL Server):
USE [<database name here>]
DECLARE @tbl_result TABLE (Result_DT DATETIME, Campaign VARCHAR(25), unit_count int);
DECLARE @start_dt DATETIME,
@current_campaign VARCHAR(25),
@record_dt DATETIME,
@campaign VARCHAR(25),
@cur_records CURSOR,
@Record_Count INT;
SET @current_campaign = 'Start'
SET @cur_records = CURSOR
FOR SELECT DateTime, Campaign FROM myTable order by 1,2
OPEN @cur_records
FETCH NEXT FROM @cur_records INTO @record_dt, @campaign
WHILE @@FETCH_STATUS = 0
BEGIN
IF @campaign <> @current_campaign
BEGIN
If @current_campaign <> 'Start'
BEGIN
INSERT INTO @tbl_result
VALUES (@start_dt, @current_campaign, @Record_Count)
END
SET @current_campaign = @campaign
SET @start_dt = @record_dt
SET @Record_Count = 1
END
ELSE
BEGIN
SET @Record_Count = @Record_Count + 1
END
END
INSERT INTO @tbl_result
VALUES (@start_dt, @current_campaign, @Record_Count)
SELECT Result_DT, Campaign, unit_count FROM @tbl_result order by 1, 2
, , , , Microsoft Box