gpt4 book ai didi

mysql - 如何根据某些条件将结果分组为串联结果

转载 作者:行者123 更新时间:2023-11-29 10:31:40 25 4
gpt4 key购买 nike

我想根据时间戳对我的结果进行分组。

演示:http://sqlfiddle.com/#!9/ab315b/1

例如,如果日期14,有3个结果,那么我希望我的输出如下所示

+                                  results                                                         +
| |
+--------------------------------------------------------------------------------------------------+
| <td> 14</td><td>project name1</td><td><p>project desc 1</p></td><td>created at 1</td> |
| <td> 13</td><td>project name2</td><td><p>project desc 2</p></td><td>created at 2</td>
| <td> 12</td><td>project name3</td><td><p>project desc 3</p></td><td>created at 2</td>
+-------------------------------------------------------------------------------------------------
| other results of same date like 13 |
+-------------------------------------------------------------------------------------------------+

根据下面的图像和查询:

enter image description here

这里我已执行: http://sqlfiddle.com/#!9/ab315b/1

请帮帮我提前致谢!!!

最佳答案

您可以在此处使用Group_concat连接多行。类似的东西

SELECT created_at, Group_concat(project_desc, ' ') FROM work_desc 
Group By CAST(created_at AS DATE)
ORDER BY created_at DESC;

它的输出看起来像

created_at  Group_concat(project_desc, ' ')
2017-11-14T10:18:54Z this my first day report employeee 2222 ,this my first day report employeee 33333 ,this my first day report employeee 44444
2017-11-12T18:30:00Z this my yesterday day report employeee 2222 ,this my yesterday day report employeee 33333

我相信您可以做一些工作来生成您正在寻找的输出。

编辑

我相信这会返回您正在寻找的输出

SELECT concat(Group_concat(concat('<tr><td>', project_name, 
'</td><td>', project_desc, '</td>')
SEPARATOR '</tr>'), '</tr>')
FROM work_desc GROUP BY CAST(created_at AS DATE)
ORDER BY created_at DESC

希望这有帮助。

关于mysql - 如何根据某些条件将结果分组为串联结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47284234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com