Skip to content
Advertisement

Is there a way to have a distinct clause and SUM clause at the same time?

I have this table in my database, which stores the data of requests made by a tool application.

It stores the information of the request(Folio), of the tools(IdHerramienta and Gasto[Cost]). My objective is to get an statement to obtain the data of the details, only showing distinct IdHerramienta(IdTool) per row, how many of them are with the same Folio, and the sum of the cost in case the IdTool gets repeated (if a tool appears multiple times with the same Folio, add its cost for each time it gets repeated)

So far I can only show how many times a tool gets repeated, but I want to get the cost too, any ideas about how to get it?

Results I want to obtain

Advertisement

Answer

You seem to be looking for aggregation:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement