Lets say, we have this table :
+------+------+
| COL1 | COL2 |
+------+------+
| A | B |
+------+------+
| B | A |
+------+------+
| C | D |
+------+------+
I want to count the number of times either letter1, letter2
or letter2, letter1
appears in the two columns.
I want the result :
+------+------+------+
| COL1 | COL2 | COL3 |
+------+------+------+
| A | B | 2 |
+------+------+------+
| C | D | 1 |
+------+------+------+
NOTE: It can be either AB
or BA
doesn't matter.
I tried:
SELECT
COL1,COL1,COUNT(*) AS COL3
FROM
X
GROUP BY COL1,COL2;
But that gets me :
+------+------+------+
| COL1 | COL2 | COL3 |
+------+------+------+
| A | B | 1 |
+------+------+------+
| B | A | 1 |
+------+------+------+
| C | D | 1 |
+------+------+------+