How mysql marks the number of repetitions of a field value

has a table, table_x, field A has a duplicate value:

now you want to return the result of the sample diagram through the select query, counting the number of times the value of the corresponding field An is repeated. The ideal effect is shown in figure

The purpose of

is to add tags, marking "first" for the first time, and then "again" for the first time, and also want to show how many times the record appears.

how can I achieve this? Thank you very much!

Mar.09,2021

Hello, I'm in the same situation as you. I figured it out. I'll tell you the method and hope to help you
table structure. Table A has an id self-growing type (there must be a different field). The result of the execution of the
statement is like this

.

select A.idjournal A.xmmc, (select count (*) as num from table A where id < = A.id and A.xmmc = xmmc) as times from table A


can you give a brief introduction to your application scenario? Because there are many solutions to this problem from different angles

< hr > < H2 > Overview < / H2 >

according to your description, I suggest that you use redis, to implement a counter function (for example, the like function of a large website, the article ID is your A, and the number of likes is your B)

< H2 > concrete implementation < / H2 >

use the INCR command. For instructions, see http://redisdoc.com/string/in.
INCR A , where An is the key, of redis, that is, the field An in your table

. < H2 > example < / H2 > The

Redis Incr command increments the numeric value stored in key.
if key does not exist, the value of key is initialized to 0 before performing the INCR operation.
if the value contains the wrong type, or if the value of the string type cannot be represented as a number, an error is returned.
the value of this operation is limited to the 64-bit (bit) signed numeric representation.
example:

127.0.0.1:6379> set num 10
OK
127.0.0.1:6379> incr num
(integer) 11
127.0.0.1:6379> get num    -sharp  Redis 
"11"
< H2 > practice proves < / H2 >

We have a web app and we want to record the number of times each user visits the site per day. The
web application only needs to incr the key by concatenating the user id and the string representing the current time as the key, each time the user visits the page.

< hr >

select A Maxima (B) from table_x group by A, gets the maximum B of each A

wouldn't it be nice to get the maximum B of each A directly. Bread1 means the first time, and B > 1 is definitely not the first time? Is that the logic


select A.iddepartment A.xmmccount (distinct A1.id) cnt from A left join A1 on A.id < = A1.id and A.xmmc=A1.xmmc group by A.id
this way of writing is more efficient, and it is easier to understand internal logical relations, and it is also easier to write, case when when you need to sort out the number of times.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be6819-317ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be6819-317ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?