MYSQL组自动编号

时间:2018-04-18 10:35:34

标签: mysql

我有一些情况:

查询:

set @rank = 0;
select @rank:=@rank+1, CONCAT_WS(" ",`Group`, SubGroup, TertiaryGroup) Items,ItemGroup, item from myTable

这是我的示例文本数据

A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition:   
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition:
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition:   
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition:       
A. CARRIER: 1. UNDERCARRIAGE: 1.1 Track System Condition:       
A. CARRIER: 1. UNDERCARRIAGE: 1.2 Final Drive System Condition:         
A. CARRIER: 1. UNDERCARRIAGE: 1.3 Transmission Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.3 Transmission Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.3 Transmission Condition:   
A. CARRIER: 1. UNDERCARRIAGE: 1.3 Transmission Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.3 Transmission Condition: 
A. CARRIER: 1. UNDERCARRIAGE: 1.3 Transmission Condition:   
A. CARRIER: 1. UNDERCARRIAGE: 1.4 Underchassis Condition:       
A. CARRIER: 1. UNDERCARRIAGE: 1.4 Underchassis Condition:   
A. CARRIER: 1. UNDERCARRIAGE: 1.4 Underchassis Condition:   
B. ENGINE SYSTEM Condition:     
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         
B. ENGINE SYSTEM Condition:         

只有这些物品对我来说足够了,谢谢,

但我需要一个结果,如果项目不同或更改,自动编号倒计时将开始为1

与我的示例图片结果一样,数字10必须返回1,下一个应该再次返回1,2,3,4,依此类推。

items列不是item

有可能吗?

提前致谢。

2 个答案:

答案 0 :(得分:1)

假设您有办法订购数据(例如auto_increment id列),您可以

$card = $manager->getCard();

$card
  ->setDueDate($due)
  ->setName('Order ' . $x[0]['job_no'] . ' [' . $x[0]['vendorAdd']. ']')
  ->setDescription($description)
  ->setPosition('top')
  ->save();

$cardId = $card->getId();

echo $cardId;

答案 1 :(得分:1)

试试这个:

set @rank = 0; set @key = ''; SELECT IF( CONCAT_WS(" ",`Group`, SubGroup, TertiaryGroup) = @key, @rank:=@rank+1, 1 ), @key:=CONCAT_WS(" ",`Group`, SubGroup, TertiaryGroup) Items,ItemGroup, item FROM myTable