Mysql - Count equal data in the same column

Asked

Viewed 30 times

-1

Good afternoon to all,

I have a table called 'ms_msg_log'. In this table, I have the columns 'id_error' and 'data_alt'. I need the data displayed as follows:

id_error = the normal value of the field,
id_error counting but summing only when they are equal,
data_alt

How the data is in the Table
Ex:


id_erro data_alt
2 11-07-21
5 11-07-21
5 11-07-21
3 12-07-21
3 12-07-21
5 12-07-21
5 12-07-21
5 12-07-21
5 12-07-21
5 12-07-21
5 12-07-21
5 12-07-21

Expected outcome of the consultation:
Ex:


id_erro count data_alt
2 1 11-07-21
5 2 11-07-21
3 2 12-07-21
5 7 12-07-21

In case you couldn’t explain it properly, I can try to convey the idea more clearly. I thank you all for your attention,

William

  • https://www.w3resource.com/mysql/aggregate-functions-and-grouping/aggregate-functions-and-grouping-count-with-group-by.php

1 answer

-1

If I can understand correctly you need a group by

SELECT id_error, COUNT(1), data_alt FROM ms_msg_log group BY id_error, data_alt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.