Answer the question
In order to leave comments, you need to log in
How to shorten same SELECT code inside SELECT?
The table consists of the following fields
customer, item, total
select web_deal.customer, (
SELECT group_concat(DISTINCT item)
) as gems, sum(web_deal.total) as spent_money
from web_deal
where web_deal.item in (
select item
from
(select web_deal.customer as customer,
web_deal.item
from web_deal
where customer IN (
select web_deal.customer from web_deal
group by web_deal.customer
order by count(web_deal.total) DESC
limit 5
)
group by web_deal.customer, web_deal.item
order by sum(web_deal.total) DESC)
group by item
having count(item) > 1
)
group by web_deal.customer
order by count(web_deal.total) DESC
limit 5
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question