Hay alguna función nativa de MySQL que me ayude a agrupar la información por días ,lo he intentado de varias maneras pero GROUP By solo me trae un resultado por día.
Esta es mi query :
const {room , year } = req.body;
SELECT * from Chat WHERE room=" + mysql.connection.escape(room) + " AND YEAR(createdAt) = " + mysql.connection.escape(year) + " GROUP BY DAY(createdAt);
Desgraciadamente, no me sirve porque como ya he dicho , solo me trae un registro del chat por día.
La otra manera que se me ocurrió, es la de tratar mi array yo mismo, creando otro array, filtrando el nuevo por fechas, y ir metiendo en el nuevo array , el resultado por fechas.
Este es mi array :
[
{
"id": 9577,
"adminId": 24,
"clientId": null,
"msg": "hola",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-08T09:04:51.000Z",
"updatedAt": "2022-04-08T07:04:49.000Z",
"day": null
},
{
"id": 9578,
"adminId": 24,
"clientId": null,
"msg": "dssa",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-08T09:04:55.000Z",
"updatedAt": "2022-04-08T07:04:53.000Z",
"day": null
},
{
"id": 9579,
"adminId": 24,
"clientId": null,
"msg": "hola",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-08T09:05:01.000Z",
"updatedAt": "2022-04-08T07:04:59.000Z",
"day": null
},
{
"id": 9580,
"adminId": null,
"clientId": 1330,
"msg": "hola",
"emisor": "Cliente",
"room": "Nirmine669217903",
"createdAt": "2022-04-08T09:05:04.000Z",
"updatedAt": "2022-04-08T07:05:02.000Z",
"day": null
},
{
"id": 9692,
"adminId": 23,
"clientId": null,
"msg": "hola",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-19T09:52:28.000Z",
"updatedAt": "2022-04-19T07:52:27.000Z",
"day": null
},
{
"id": 9693,
"adminId": 23,
"clientId": null,
"msg": "que tal",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-19T09:52:30.000Z",
"updatedAt": "2022-04-19T07:52:30.000Z",
"day": null
},
{
"id": 9694,
"adminId": 23,
"clientId": null,
"msg": "hola",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-19T11:02:42.000Z",
"updatedAt": "2022-04-19T09:02:42.000Z",
"day": null
},
{
"id": 9695,
"adminId": 23,
"clientId": null,
"msg": "que tal estas??",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-19T11:02:46.000Z",
"updatedAt": "2022-04-19T09:02:45.000Z",
"day": null
},
{
"id": 9696,
"adminId": 23,
"clientId": null,
"msg": "estas??",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-19T11:02:50.000Z",
"updatedAt": "2022-04-19T09:02:50.000Z",
"day": null
},
{
"id": 9697,
"adminId": 23,
"clientId": null,
"msg": "hola",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-19T11:02:52.000Z",
"updatedAt": "2022-04-19T09:02:52.000Z",
"day": null
},
{
"id": 9698,
"adminId": 23,
"clientId": null,
"msg": "hola",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-20T06:07:08.000Z",
"updatedAt": "2022-04-20T04:07:06.000Z",
"day": null
},
{
"id": 9699,
"adminId": 23,
"clientId": null,
"msg": "estas??",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-20T06:07:09.000Z",
"updatedAt": "2022-04-20T04:07:08.000Z",
"day": null
},
{
"id": 9700,
"adminId": 23,
"clientId": null,
"msg": "hola+",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-20T06:14:36.000Z",
"updatedAt": "2022-04-20T04:14:34.000Z",
"day": null
},
{
"id": 9701,
"adminId": null,
"clientId": 1359,
"msg": "Hola rocio,mi nombre es Eva, ¿En que puedo ayudarte?",
"emisor": "Cliente",
"room": "Nirmine669217903",
"createdAt": "2022-04-20T06:21:57.000Z",
"updatedAt": "2022-04-20T04:21:55.000Z",
"day": null
},
{
"id": 9702,
"adminId": 23,
"clientId": null,
"msg": "Hola rocio,mi nombre es Eva, ¿En que puedo ayudarte",
"emisor": "Admin",
"room": "Nirmine669217903",
"createdAt": "2022-04-20T06:46:56.000Z",
"updatedAt": "2022-04-20T04:46:55.000Z",
"day": null
}
]
Alguien tiene otra forma de hacerlo ??'
Gracias