Need a query to find total distance with some condition?
03:38 11 Oct 2018

I have two tables in my database, One is category, and second is an entry table.

My Category Table is like below:

----------------------------------
| Cat_ID |  cat_type | cat_value |
----------------------------------
|  201   |  running  |     1     |
|  202   |  cycling  |     4     |
----------------------------------

My Entry Table is like below:

-------------------------------
| user_id | cat_ID | distance |
-------------------------------
|    1    |   201  |    50    |
|    1    |   201  |    50    |
|    1    |   202  |   100    |
|    1    |   202  |   100    |
|    2    |   201  |    10    |
|    2    |   201  |    10    |
-------------------------------

So Now I want to total distance for user ID "1" but here one condition is that for 201 categories the sum of the total will divide by one and for 202 category total distance will divide by 4 as per category table in cat_value.

Means I want total distance like ((50+50)/1 + (100+100)/4)

So, how can I do this?

mysql