I have a database with this kind of a table, has more than 10 million rows.
ID colA colB Length
1 seq1 seq11 1
2 seq1 seq11 11
3 seq3 seq33 21
4 seq3 seq33 14
I want to loop though colA first, get the relevant colB value, and check if there are any other occurrences of the same value.
For example in colB (seq11) there are 2 occurrences of colA(seq1), this time I have to combine those and output the sum of the length. Similar to this:
ID colA colB Length
1 seq1 seq11 12
2 seq3 seq33 35
I am a bit Java guy, but because my colleague has written everything in PHP and this will be just an adding, I need a PHP solution.
With Java I would have used hashmap, so that I would have the colA data once and just increment the value of “Length Column”.
I tried this query in order to group by occurences:
SELECT COUNT(*) SeqName FROM SeqTable GROUP BY SeqName HAVING COUNT(*)>0;
In PHP you can use an array like an hash map
Or you can use an SQL query like this one: