4
I have 6 SQL codes and all search in the same table, it looks like this:
+-----+-----+-----+
| A | B | C |
+-----+-----+-----+
| 1 | 1 | 1 |
+-----+-----+-----+
| 2 | 1 | 5 |
+-----+-----+-----+
| 3 | 2 | 3 |
+-----+-----+-----+
| 4 | 1 | 1 |
+-----+-----+-----+
| 5 | 1 | 4 |
+-----+-----+-----+
| 6 | 1 | 5 |
+-----+-----+-----+
| 7 | 9 | 1 |
+-----+-----+-----+
| 8 | 3 | 1 |
+-----+-----+-----+
And the codes are these:
SELECT COUNT(*) as total, SUM(C) as soma FROM tabela WHERE B = 1;
SELECT COUNT(*) as total1 FROM tabela WHERE B = 1 AND C = 1;
SELECT COUNT(*) as total2 FROM tabela WHERE B = 1 AND C = 2;
SELECT COUNT(*) as total3 FROM tabela WHERE B = 1 AND C = 3;
SELECT COUNT(*) as total4 FROM tabela WHERE B = 1 AND C = 4;
SELECT COUNT(*) as total5 FROM tabela WHERE B = 1 AND C = 5;
The values returned are these:
total = 4
total1 = 2
total2 = 0
total3 = 0
total4 = 1
total5 = 2
soma = 16
Everything works perfectly, but would need everything to return in the same query, it is possible?
The intention is to count how many rows are in the table, whose column B is equal to a value, then return in "total" and sum all the values in column C and return in "sum", but need it to return the amount of times a value repeats in the search.