Forum Moderators: open
I had table records as :
+-------+--------+--------+
¦urlid1 ¦ urlid2 ¦jobcount¦
+-------+--------+--------+
¦129147 ¦130676 ¦ 305 ¦
¦130676 ¦129147 ¦ 72 ¦
¦130676 ¦129149 ¦ 756 ¦
¦129149 ¦130676 ¦ 30 ¦
+-------+--------+--------+
Now, i need to club the records, where urlid1 = urlid2 and urlid2 = urlid1 and take the job count for those records.
Means that 1st record of urlid1(129147) should search the column urlid2 and also vice versa and finally it should sum the jobcount column.
Expected output:
+-------+--------+--------+
¦urlid1 ¦ urlid2 ¦jobcount¦
+-------+--------+--------+
¦129147 ¦130676 ¦ 377 ¦
¦130676 ¦129149 ¦ 786 ¦
+-------+--------+--------+
I tried several combinations but all in vain.
SELECT a.urlid1, sum( a.jobcount )
FROM test AS a
JOIN test AS b ON a.urlid1 = b.urlid2
AND a.urlid2 = b.urlid1
GROUP BY a.urlid1
any ideas would be great help.
Thanks
This will solve you problem.
Let me know if you get it or not.
All the best