I have a table that has partner id followed by multiple column combinations. My task is to count how many partners, each of those combinations have.
Here is an example of a table I'm working with:
And here is what I am looking to do:
Does anyone knows how to sort this out?
thanks
CodePudding user response:
SELECT
MAX(COMB_1) AS COMB_1,
MAX(COMB_2) AS COMB_2,
MAX(COMB_3) AS COMB_3,
MAX(CATEGORY) AS CATEGORY,
COUNT(*) AS PARTNER_COUNT
FROM NoOneNamesTheirTableInSQLQuestions
GROUP BY CONCAT_WS(';', COMB_1, COMB_2, COMB_3);
This uses a MySQL function CONCAT_WS()
, but there should be equivalent ways of doing this in each of the other databases you tagged your question: Oracle and SQLite.