I do not have much experience in SQL and I'm making a mess to solve something that almost certainly is not very complex.
I have a table that has a column with an alphanumeric code:
columnA {xa1, xa2, xa3, xa3, xa3, xa4, xa4, xa5, xa6, xa6, etc.}
I am trying to create a new table that tells me the following:
As of xa1, xa2 i xa5 there is 1 in each case, I have 3 events of 1, 1 event of 3 reptocations (xa3), 2 events of 2 repetitions (xa4, xa6).
I have managed to create the table that tells me the number of events of each code:
SELECT rules.codventa,
COUNT(rules.codventa) AS sum INTO suma
FROM rules
GROUP BY rules.codventa
ORDER BY rules.codventa DESC;
I have something like this:
- xa1 - 1
- xa2 - 1
- xa3 - 3
- xa4 - 2
- xa5 - 1
- xa6 - 2
Now I can not get the final table that says:
- 1 - 3
- 2 - 2
- 3 - 1
Any ideas?
Thanks
EDIT: add the creation code of the table
CREATE TABLE gourmet.rules
(
codventa character(25) NOT NULL,
nombretienda character(100) NOT NULL,
codproducto character(100) NOT NULL,
unidades smallint NOT NULL,
precioventa numeric(8,4) NOT NULL
)
The primary key corresponds to coding