OK, I found out about `sequelize.cast` so I can convert to integers however: as my error message was containing the following:
`[RequestError: Column '
Domain.ReportType.Id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.]`
I modified my query to this:
reportInfo.findAll({
attributes: [sequelize.cast(sequelize.col('CreatedOn'), 'DATE'), [sequelize.fn('count', sequelize.col('IsDownloaded')),'Total'], [sequelize.fn('sum', sequelize.cast(sequelize.col('isInLive'), 'INTEGER')), 'InLive' ]],
group: ['ReportType.Id']
}],
group: [sequelize.cast(sequelize.col('CreatedOn'), 'DATE'), 'ReportInfo.Id', 'ReportType.Code','ReportType.Id'],
order: [
[sequelize.cast(sequelize.col('CreatedOn'), 'DATE'), 'DESC']
]
})
However this doesn't give a satisfactory output: and generated the following:
CAST([CreatedOn] AS DATE),
count([IsDownloaded]) AS [Total],
sum(CAST([isInLive] AS INTEGER)) AS [InLive],
[ReportType].[Id] AS [ReportType.Id],
[ReportType].[Code] AS [ReportType.Code]
FROM [Domain].[ReportInfo] AS [reportInfo]
INNER JOIN [Domain].[ReportType] AS [ReportType] ON [reportInfo].[ReportTypeId] = [ReportType].[Id]
AND [ReportType].[Code] LIKE N'10%'
GROUP BY CAST([CreatedOn] AS DATE), [ReportInfo].[Id], [ReportType].[Id], [ReportType].[Code]
ORDER BY CAST([CreatedOn] AS DATE) DESC;
Final output:
`Problem trying to retrieve data: [TypeError: Cannot read property 'forEach' of undefined]`
Why is `Id` selected in the main and subquery? How can avoid to have them selected and also how can I avoid the selection of the attribute of the subquery (`ReportType.Code`) ?