CodeIgniter Forums
Help with MySQL statistics with Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Help with MySQL statistics with Codeigniter (/showthread.php?tid=68200)



Help with MySQL statistics with Codeigniter - gbwebapps - 06-08-2017

I have this scenario in my application: a database with 4 main tables. They are:

brands
categories
categories_to_product
products

Between brands table and products table there is a one to many relation. Of course, there is a join field in products table that let me to relate the two tables named brand_id.

Between categories table and products table there is a many to many relation, and both tables use the categories_to_product table for to have the many to many relation. In the join table there is a composed PK with two fields, category_id and product_id.

So far so good.

Now, my goal is to have some statistics, and this is a field too difficult for my sql knowledge.

I'd like to achieve this kind of data:
- the first ten brands with more products related
- the first ten categories with more products related

I neither know from where I have to start, can someone tell me in what direction do I Have to go for to start?

Thank you in advance.

Giorgio.


RE: Help with MySQL statistics with Codeigniter - neuron - 06-08-2017

(06-08-2017, 09:28 AM)gbwebapps Wrote: I'd like to achieve this kind of data:
- the first ten brands with more products related
- the first ten categories with more products related

Can u explain this more clearly. more products related? related to what?


RE: Help with MySQL statistics with Codeigniter - gbwebapps - 06-08-2017

The brands with more products related with itselves
The categories with more products related with itselves

for example...

1) samsung(22)
2) apple(19)
3) hewlett packard(13)
.....
.....

or

1) smartphones(22)
2) tablets(19)
3) pc desktop(13)

between parentheses the number of the products related....