Skip to content
Advertisement

How to combine these two queries from different tables into one to calculate percentage?

I have the following query which has the students attendance in the period:

And I have the lesson count in the same period.

I’d like to divide total_presences by lessons count to get the students attendance percentage.

How do I do that in a single query?

Advertisement

Answer

Probably the easiest way is to use a CTE:

Depending on the type of total_presences, you may have to cast it to numeric, real, or float to avoid integer math.

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