Reputation: 43
How to do group by if the value of the next column is the same, later I will calculate how long the purchase will take, later added per group
Upvotes: 0
Views: 612
Reputation: 176
User COUNT
with GROUP BY
to achieve it.
SELECT BUAH, COUNT(*) AS Total FROM your_table GROUP BY `WAKTU BELI`
Upvotes: -2
Reputation: 82020
This is a classic Gaps-and-Islands Problem.
In the future, please provide sample data as TEXT not as an image.
Example
with cte as (
Select *
,Grp = row_number() over (order by ID)
-row_number() over (partition by BUAH order by ID)
From YourTable
)
Select BUAH
,Cnt = sum(1)
From cte
Group By BUAH,Grp
Order By min(ID) --<< Optional
Results
BUAH Cnt
APEL 2
TOMAT 2
APEL 3
...
Upvotes: 6