Hi, I am enjoying prisma a lot, thanks for making...
# orm-help
a
Hi, I am enjoying prisma a lot, thanks for making it so easy to use. I was wondering what the best approach is to sum a column in a table, but have the sums grouped by a distinct relation. For example, imagine you had a table of stockTrades, and each stockTrade row had a relation to a user who made the trade. Another column is the profit/loss for that trade. What is the most efficient way to grab each distinct user, and sum their total profit/loss? The only way I could think of was to grab each distinct user in one query, and then loop through each user and count each profit/loss, but that would create 1 query per user in the table which wouldn't scale well. Thanks for any help!
r
@Ash B πŸ‘‹ I think you would need to do this with a raw query as we don’t support aggregations like sum with distinct. It would be great if you could create a feature request here so that we can look into this πŸ™‚
a
@Ryan Thanks, I managed to get a raw SQL query to work. I'll make sure I submit that request soon πŸ‘
πŸ’― 1