本文介绍了如何给MySQL中的记录组提供相同的序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是mysql的新手.我在购物车表格中有以下记录

I am just new in mysql. I have records like below in carts table

 id   code
 1     100
 2     101
 3     102
 4     100
 5     100
 6     101

我的例外输出如下:-

id     code    serial_number
 1     100        1
 2     101        2
 3     102        3
 4     100        1
 5     100        1
 6     101        2

我想要属于同一组的相同序列号,即代码.谁能帮我怎么做?

I want same serial number that is belongs to same group i.e code. can anyone help me how to do?

推荐答案

根据您的示例,您的代码始终具有相同的序列号.那你会得到什么?

According to your example you always have the same serial number for a code. So what do you gain?

这是非常简单的查询:

select id, code, code - 99 as serial_number
from mytable
order by id;

这篇关于如何给MySQL中的记录组提供相同的序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 23:33