I have two tables, one contains data like this:
link_id | counted
=================
1--------| 1
==================
2------- | 0
==================
3 -------| 1
===================
I want to select those that are counted = 1, and then with the ids here I want to go to the table link (whose ids are in the link_id table above), and multiply each by its corresponding factor:
id | factor
===========
1 | 0.3
============
2 | 0.1
===========
3 | 0.5
==========
So for the values above it would be:
counted = 1 in first table, 1 and 3.
Now,
1*0.3 + 3*.5 = 0.3+1.5 = 1.8
How can I do this with a MySQL query?
1 Answer