+-------+---------+----------+---------------+-------------+-----+
| serial| amount | NameOfMyFriends |
+-------+---------+----------+---------------+-------------+-----+
| 1 | 1500.00 | FOOBAR1, FOOBAR2, FOOBAR3, FOOBAR4, FOOBAR5, |
| 2 | 2000.00 | FOOBAR1, FOOBAR3, FOOBAR4, FOOBAR5, |
| 3 | 300.00 | FOOBAR1, FOOBAR2, |
| 4 | 600.00 | FOOBAR2, FOOBAR4, |
| 5 | 900.00 | FOOBAR4, FOOBAR5, |
| 6 | 800.00 | FOOBAR2, FOOBAR5, |
| 7 | 600.00 | FOOBAR1, FOOBAR3, |
+-------+---------+----------+---------------+-------------+-----+
I need to find each one's share something like this:
Using JavaScript how can I extract data like this, without using any JavaScript Library?
I am answering this as a SQL question because it is tagged MySQL.
This is an awful data format. You should have a separate association table, with one row per serial and friend.
But, if you have a friends table, then you can get what you want using MySQL:
select f.FriendName, sum(eachVal)
from YourTable t join
Friends f
on find_in_set(f.FriendName, t.NameOfMyFriends) > 0
group by f.FriendName;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With