检索按成员分组的每日竞赛条目

发布于 2024-10-25 14:55:27 字数 561 浏览 5 评论 0原文

这是我的上一个问题的后续问题,我正在写这个问题会员网站的 PHP 竞赛脚本,限制每位会员每天只能参加一次。

这些条目存储在具有以下结构的“competition_entries”表中:

ce_id: primary key 
ce_c_id: competition ID
ce_sub_id: member ID
ce_date: date stamp for the entry

我想编写一个 MySQL 查询来检索每个成员的条目数,

Member A: 4 entries
Member C: 2 entries
Member Y: 23 entries
etc...

但我不知道如何做到这一点。 TIA。

编辑:如果它不明显,我意识到我需要将会员 ID 关联回另一个表以检索他们的用户名 - 我可以做这一点(抱歉,漫长的一天):)

this is a followup to my previous question, whereby I'm writing a PHP competition script for a members site that restricts entries to one per day per member.

The entries are stored in a table "competition_entries" with the following structure:

ce_id: primary key 
ce_c_id: competition ID
ce_sub_id: member ID
ce_date: date stamp for the entry

I would like to write a MySQL query that retrieves number of entries per member, i.e.

Member A: 4 entries
Member C: 2 entries
Member Y: 23 entries
etc...

but am struggling as to how to do so. TIA.

EDIT: In case it's not obvious, I realise I need to relate the member ID back to another table to retrieve their username - that bit I can do (sorry, long day) :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2024-11-01 14:55:38

我认为这个查询应该为您做这件事:

SELECT COUNT(ce_sub_id) FROM competition_entries 
WHERE ce_c_id = '$competition_id' 
GROUP BY ce_sub_id

您应该有一个结果集,其中包含成员 ID 以及他或她所做的条目数。然后,您可以循环遍历结果,并以您描述的格式输出它们。

I think this query should do it for you:

SELECT COUNT(ce_sub_id) FROM competition_entries 
WHERE ce_c_id = '$competition_id' 
GROUP BY ce_sub_id

You should have a result set with a member id and the number of entries he or she has made. You can then loop through your results, and output them in the format you described.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文