简体   繁体   English

每天显示记录

[英]Display records per day

I have a table like this: 我有一张这样的桌子:

id | date | name 

And the desired output is displaying the record per day of the month: 所需的输出显示每月的每天记录:

Day 1 - name1 , name2, name3
Day 2 - name4
Day 3 - name5, name6
.
.
.

I know how to do this with php but I wonder If it is possible to do it with a mySQL sentence .. 我知道如何用php做到这一点,但我想知道是否可以用mySQL语句来做到这一点。

Anyone can help? 有人可以帮忙吗?

Try this: 尝试这个:

SELECT DAYOFMONTH(date) AS Day, GROUP_CONCAT(name SEPARATOR ', ') AS Name
FROM table1
GROUP BY Day

Working demo: http://sqlfiddle.com/#!2/ecc33/1 工作演示: http : //sqlfiddle.com/#!2/ecc33/1

Select date,group_concat(name) from table1 group by date 

尝试这个。

Using GROUP_CONCAT () alows you to do that: 使用GROUP_CONCAT ()可以做到这一点:

SELECT date,group_concat(name)
FROM tableName
GROUP BY date

The group in this query will be done by date, not the day of the month. 此查询中的组将按日期而不是月份中的日期完成。 If you have one record in 2013-01-01 it will not be in the same group as 2013-02-01 . 如果您在2013-01-01有一个记录,它将与2013-02-01不在同一组中。 If that is what you are looking for, @Aziz's answer is what you are looking for. 如果这是您要寻找的,@ Aziz的答案就是您要寻找的。

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

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