Skip to content
Advertisement

how to write group-by query SQL with quantity unit conversion?

How to write SQL query to sum(quantity) in certain unit (such as bottle in the example)?

can a database function such as getRate(unit1, unit2) do the job? how about the performance?

Advertisement

Answer

You need to expand the conversion table so it has all combinations. This is a one time effort, but you need to add rows like this:

Then you can use a LEFT JOIN:

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