Is it possible to do a `case when` inside the aggr...
# orm-help
r
Is it possible to do a
case when
inside the aggregation sum from Prisma client? Something like:
Copy code
SELECT 
	title,
	SUM(CASE WHEN some_date <= date('YYYY-MM-DD') THEN amount
		ELSE 0 END)
FROM test
GROUP BY title;
🍿 1
So I know that in Sequelize I can do the following:
Copy code
await Model.findAll({
    attributes: [
        "field1", 
        "field2", 
        "field3",
        [sequelize.cast(sequelize.fn('sum', sequelize.literal(`CASE WHEN field4 ... END`)), "varchar"), "total"],
    ],
    group: ["field1", "field2", "field3"],
    order: ["field1", "field2", "field3"],
});
with a literal inside an fn. I am aware of the groupBy function in Prisma, but can someone explain how I can retain more fine-grained control over the sum here?
Copy code
await prisma.model.groupBy({
    sum: {
        field4: true,
    },
    by: ["field1", "field2", "field3"],
    orderByy: ["field1", "field2", "field3"],
});