Call a SQL procedure, for each group by
I'm not sure I get your question, but not enough reputation to comment. Thus, I'll make some assumptions and answer to the best of my understanding with them.

For example with SQLite (this is one of the simplest, variations possible in different dialects), let's assume your data is created with:

CREATE TABLE "Customer" (
  id INTEGER NOT NULL, 
  name VARCHAR(64) NOT NULL, 
  PRIMARY KEY (id), 
  UNIQUE (id)
);

CREATE TABLE "Movie" (
  id INTEGER NOT NULL, 
  customer INTEGER NOT NULL, 
  movie VARCHAR(64) NOT NULL, 
  PRIMARY KEY (id), 
  UNIQUE (id), 
  FOREIGN KEY(customer) REFERENCES "Customer" (id)
);


Let's populate with some data:

INSERT INTO Movie (id, customer, movie) VALUES(0, 0, 'Rambo');
INSERT INTO Movie (id, customer, movie) VALUES(1, 0, 'Rocky');
INSERT INTO Movie (id, customer, movie) VALUES(2, 1, 'Mamma Mia');
INSERT INTO Movie (id, customer, movie) VALUES(3, 1, 'Grease');
INSERT INTO Movie (id, customer, movie) VALUES(4, 0, 'Terminator');


As long as you are happy with applying some aggregate functions, you can just use a single SELECT like this:

SELECT
  customer, MAX(id),
  COUNT(DISTINCT id), AVG(LENGTH(movie)), SUM(LENGTH(movie))
FROM Movie GROUP BY customer;


If you need to get data from the Customer table, you might need to make a join like this:

SELECT
  Customer.name, Customer.id, MAX(Movie.id),
  COUNT(DISTINCT Movie.id), AVG(LENGTH(Movie.movie)), SUM(LENGTH(Movie.movie))
FROM Movie
JOIN Customer on Movie.customer=Customer.id
GROUP BY customer;


If you want to do k-means, SQLite is quite limited, but with other dialects you can still do it. See this paper for an example. On the internet one can easily find examples in PostgreSQL, MySQL, SQL Server,... you could google yours.

Most other SQL dialects would have a richer set of predefined functions. For more complicated analysis you might need to define your own functions, and probably work with the results out of your SQL.