简体   繁体   English

对SQL列进行分组并计算结果

[英]Group SQL Columns and count the results

How can I sort my database results into something like this using PHP. 如何使用PHP将数据库结果排序为类似的格式。 Basically, I am trying to group the results, and then count the results found in the database. 基本上,我试图将结果分组,然后对在数据库中找到的结果进行计数。

  • Starcraft (1) 星际争霸(1)

  • League of Legends (4) 英雄联盟(4)

  • Minecraft (2) 我的世界(2)

  • Call of Duty: Black Ops (1) 使命召唤:黑色行动(1)

I know there is a way, but I can't figure out the logic for this situation. 我知道有办法,但是我无法弄清楚这种情况的逻辑。 If someone can give me an insight, that would be nice. 如果有人可以给我一个见识,那就太好了。 Thank you! 谢谢!

Here is my SQL Table: 这是我的SQL表:

在此处输入图片说明

Looks like a straightforward count and group by statement: 看起来很简单,可以按语句分组:

select
    game,
    count(*)
from
    yourTable
group by
    game

Based on this question, you should really take a read of this question and answer I wrote for situations like this as it explains in a lot of detail what is going on and how to get the results you want. 基于这个问题,您应该真正阅读我针对类似情况写的这个问题和答案,因为它详细解释了正在发生的事情以及如何获得所需的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM