Generating unique ids for a group of rows and incr

2019-09-19 09:24发布

Hi I am trying to create a table where I can generate a unique id for a group of rows and it should increment for each group of entry in MySql. Please help, thanks

For example: This is how it should look like after enetring rows.

Sample_id   Sample_No   Results    Sample_Name 
1              1           abc         xyz
1              1           bca         xyz
1              1           hjk         xyz
2              2           abc         xyz
2              2           bca         xyz

3              1           abc         abc
3              1           hjk         abc
4              2           abc         abc
4              2           hjk         abc

5              1           abc         hjk
5              1           hjk         hjk

Answer is in the image please view for a better understanding

NOTE :I am pushing data from an excel workbook and Sample no 1 and 2 are pushed together at the same time which should autogenerate sample_id as 1 and 2 resp. While the next sample_No 1 and 2 is pushed another time which should generate Sample_id as 3 and 4 while Sample_id 5 is generated when I push Sample_No 1. The sample_id is not the primary key, I will have another column as a primary key which will be just 'id'which will be unique for each row.

Please help me, I am new to MySQL and trying to solve this since a long time. Thanks.

Sorry for the bad formatting.

0条回答
登录 后发表回答