We have two columns in a table customer in which we have customer id and the service id in those. So, every customer using multiple services, we have to find the maximum count of the consecutive services used by the customers.
create table customer(id int not null auto_increment,customerid varchar(20), serviceid varchar(20),primary key(id));
insert into customer(customerid,serviceid) values('Nitesh','Mobile');
insert into customer(customerid,serviceid) values('Nitesh','Mobile');
insert into customer(customerid,serviceid) values('Nitesh','Landline');
insert into customer(customerid,serviceid) values('Nitesh','Broadband');
insert into customer(customerid,serviceid) values('Nitesh','Mobile');
insert into customer(customerid,serviceid) values('Nishant','Mobile');
insert into customer(customerid,serviceid) values('Nishant','Landline');
insert into customer(customerid,serviceid) values('Nishant','Landline');
insert into customer(customerid,serviceid) values('Nishant','Landline');
insert into customer(customerid,serviceid) values('Nishant','Broadband');
insert into customer(customerid,serviceid) values('Soe','Mobile');
insert into customer(customerid,serviceid) values('Soe','Mobile');
insert into customer(customerid,serviceid) values('Soe','Landline');
insert into customer(customerid,serviceid) values('Soe','Broadband');
insert into customer(customerid,serviceid) values('Soe','Mobile');
I have to count the maximum service used by the customer consecutively.
Output:
Customerid|Serviceid|ServiceidCount
----------------------------------
Nitesh|Mobile|2
Nishant|Landline|3
Soe|Mobile|2