Count on same value from different columns in same table

I have table in mysql database having below values:

src dst calldate

923 901 2015-09-03
923 923 2015-09-03
923 901 2015-09-03
901 901 2015-09-03
923 901 2015-09-03
923 901 2015-09-03
901 901 2015-09-03
923 901 2015-09-03
901 923 2015-09-03
923 901 2015-09-03
923 901 2015-09-03
923 923 2015-09-03
901 911 2015-09-03

I want to query table so i get counter of same values for both src_count and dst_count. For an example if i count for “923” it should count occurances of 923 in src and dst as below.

MySQL Query:
Select src as number, count(src) as src_count, count(dst) as dst_count from mytable group by src

Result should be:

number src_count dst_count datetime name
923 9 3 2015-09-03 Mr. T1

SELECT calldate , 'src' AS type , src AS code , COUNT(*) AS count FROM daTable GROUP BY calldate , src UNION ALL SELECT calldate , 'dst' AS type , dst AS code , COUNT(*) AS count FROM daTable GROUP BY calldate , dst ORDER BY calldate , type , code

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.