You need to make a request that will calculate and simultaneously display data. For a better understanding of my thoughts, I will provide an example below. There is a table in which there is data
id_post | name 1 | test1_1 1 | test1_2 2 | test2_1 2 | test2_2 2 | test2_3 3 | test3_1 3 | test3_2
As a result, I need to calculate the same id_post and display the data in this form
id_post | name 2 | test1_2 3 | test2_3 2 | test3_2
select distinct id_post from table_name
, orselect id_post, name from table_name group by id_post
- mysql allows you to do so without aggregate functions on the name, only it chooses an arbitrary value (it will be more correct to think so than to assume that it chooses the first, if only because that sorting is not explicitly set here) - BOPOHselect post_id, count(1) as cnt from table_name group by post_id
- as a result, get post_id with its quantity in cnt - BOPOH