Given below table called table
+---+---+
| x | y |
+---+---+
| 1 | 2 |
| 1 | 5 |
| 5 | 2 |
| 5 | 1 |
+---+---+
I want to have sql query for the following results
+----+-------------+
| id | count_total |
+----+-------------+
| 1 | 3 |
| 2 | 2 |
| 5 | 3 |
+----+-------------+
Note: I was able to count separately the rows per id but I could not get the sum for the same id. so I want to combine or get sum of below queries in a single query.
SELECT x, count(*) as total_x FROM table GROUP BY x
SELECT y, count(*) as total_y FROM table GROUP BY y