This is interesting. I think you will need something like this:
SELECT MAX(date_trans), MAX(time_trans), MAX(price), COUNT(*) FROM (SELECT *, ROW_NUMBER() OVER(PARTITION BY price ORDER BY date_trans, time_trans) - ROW_NUMBER() OVER(ORDER BY date_trans, time_trans) AS grp FROM transactions) grps GROUP BY grp
Found a solution here: http://www.sqlmag.com/article/sql-server/solution-to-the-t-sql-puzzle-grouping-consecutive-rows-with-a-common-element
UPDATE
The price should also be included in the grouping column, otherwise the groups may not be unique. Another thing is that the date and time column must be combined into a datetime column, so the maximum datetime value will be correct in groups that start at the end of one day and end at the beginning of the next. Here's the adjusted query.
SELECT MAX(CAST(date_trans AS DATETIME) + CAST(time_trans AS DATETIME)) , MAX(price), COUNT(*) FROM (SELECT *, CAST(ROW_NUMBER() OVER(PARTITION BY price ORDER BY date_trans, time_trans) - ROW_NUMBER() OVER(ORDER BY date_trans, time_trans) AS NVARCHAR(255)) + '-' + CAST(price AS NVARCHAR(255)) AS grp FROM transactions ORDER BY date_trans, time_trans) grps GROUP BY grp
A query may be more optimal with a grp column as a byte array or bigint instead of nvarchar. You also mentioned the “volume” column, which you probably want to summarize within the group.
source share