如何计算每个类别的项目?

编程入门 行业动态 更新时间:2024-10-28 21:18:28
本文介绍了如何计算每个类别的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想对网站上的产品进行过滤. 像这样:

I want to make a filtering of products on a site. Something like this:

Department - lassics (13,395) - Literary (111,399) - History (68,606) ... Format - HTML (3,637) - PDF (8) - Audio CD (443) ... Language - English (227,175) - German (10,843) - French (10,488) ...

如何计算每个类别的产品?对于每个类别,单独的SQL查询将太慢,因为产品和类别过多.我建议也不要选择缓存.

How to count products per category? A separate SQL-query for each category would be too slow because there are too many products and categories. I suggest caching is not an option too.

使用MySQL EXPLAIN查询也许有意义(尽管它并不总是提供足够的信息)?还是使用狮身人面像搜索引擎进行计数?...最好的方法是什么?谢谢.

Maybe it makes sense to use MySQL EXPLAIN queries (though it not always provide adequate information)? Or maybe using sphinx search engine for counting?... What is the best way to do this? Thanks.

推荐答案

尝试:

SELECT category, COUNT(*) as count FROM table GROUP BY category

响应应该是所有不同的category值,以及每个值的出现次数.

The response should be all the different category values, and the number of occurrences of each.

更多推荐

如何计算每个类别的项目?

本文发布于:2023-10-26 08:13:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529602.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类别   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!