Hello! I need help figuring out how to extract a r...
# orm-help
a
Hello! I need help figuring out how to extract a report with prisma. I have a table of workers and I need to count how many registers have been created each month. I have a
createdAt
date that I think I should group by, but I need it to be grouped by the year-month of this date, ignoring the day/time. With Postgres I think the
DATE_TRUNC('month', createdAt)
would be perfect but I'm not allowed to group by that on Prisma. I even tryied to cast it to
Prisma.WorkerScalarFieldEnum
but in the runtime it told me this wasn't allowed. Really would appreciate any guidance someone could provide me to achieve that, specially if I don't have to change the database schema for that 😅 Here's what my best attempt looks like:
a
Hey Ayrton 👋 , It’s not possible to mix SQL statements with Prisma queries today. You would need to write the whole query with
$queryRaw
(https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access#queryraw) to get this functionality.