S
S
Sergey Popov2018-04-02 18:39:04
SQL
Sergey Popov, 2018-04-02 18:39:04

How to display popular products from the database?

Good afternoon.
I'm sitting dumb, I can't think of a way, although it would seem obvious.
I have two tables: a product and a cart (essentially a relationship between a user, a product, and a couple more entities).
How can I display the most popular product using the number of purchases of this product (i.e. cart)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
awesomer, 2018-04-02
@be_a_dancer

obviously, you need to do this very quickly so that the user does not have to wait, so as not to load the site.
if you sum up all the sales from the basket, and then sort by this field, you will get the result.
but it will be wildly slow. and the more sales there are (the more accurate the prediction) - the slower it will be.
IMHO, it is better to separate the operations of determining the most popular product (doing it in the background, according to cron, is a long operation).
and the output is simply based on the ready flag, which will be set in the previous operation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question