I have a table called "User" where it has the details or user_id and product_item_code.
ex:
Select * from Users limit 5;
+----+---------+---------------------------+
| id | user_id | product_item_code |
+----+---------+---------------------------+
| 1 | 123 | {556,772,945} |
| 2 | 124 | {556,965,945,990} |
| 3 | 125 | {772, 435, 990, 556} |
| 4 | 126 | {556, 623, 842} |
| 5 | 127 | {842, 990, 556, 623, 745} |
+----+---------+---------------------------+
I want to count these product_item_code 556, 990, 623. How many times it's been repeated.
I am looking for a query to give me an output like below
+-------------------+-------+
| product_item_code | count |
+-------------------+-------+
| 556 | 5 |
| 990 | 3 |
| 623 | 2 |
+-------------------+-------+
I have tried the below code but couldn't get the expected output.
select count(1) from Users where ARRAY[556, 990, 623] @> ANY(product_item_code);
Please let me know how can I get the above output. Thanks in advance
count(1)is actually slower thancount(*)