I have a table of Calendar event information (Date, username).
我有一个日历事件信息表(日期,用户名)。
I want to print the following information for each "event" for a selected month in a table, using PHP and MySQL:
我想使用PHP和MySQL为表中选定月份的每个“事件”打印以下信息:
SELECT DAYOFWEEK( eventDate ) AS
DAY , YEAR( eventDate ) AS YEAR, `primary` , secondary, weekend
FROM eventcal
WHERE region = 4
AND MONTH( eventDate ) =7
ORDER BY DAYOFWEEK( eventDate )
There can be multiple users associated with a given day. What's the best way to, using MySQL and PHP, build the table so that the usernames sharing a common day are merged together? For example, instead of:
可能有多个用户与某一天相关联。使用MySQL和PHP的最佳方法是,构建表以便共享共同日期的用户名合并在一起?例如,而不是:
June | 7 | 2009 | doej2
June | 7 | 2009 | smithj2
June | 8 | 2009 | mccoyj2
I want...
June | 7 | 2009 | doej2, smithj2
June | 8 | 2009 | mccoyj2
Any ideas?
2 个解决方案
#1
Same question as: Grouping in SQL
同样的问题:在SQL中分组
Suggested was to use MySQL's GROUP_CONCAT
建议使用MySQL的GROUP_CONCAT
#2
GROUP_CONCAT is your keyword. Example : http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
GROUP_CONCAT是您的关键字。示例:http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
#1
Same question as: Grouping in SQL
同样的问题:在SQL中分组
Suggested was to use MySQL's GROUP_CONCAT
建议使用MySQL的GROUP_CONCAT
#2
GROUP_CONCAT is your keyword. Example : http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
GROUP_CONCAT是您的关键字。示例:http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/