I have a login log table, its already define a id (auto increment) as primary key! but it's very difficult to catch each user data. let's see that table demo below.
+----+------+--------+
| id | uid | money |
+----+------+--------+
| 1 | 101 | 200.00 |
| 2 | 101 | 100.00 |
| 3 | 102 | 300.00 |
| 4 | 102 | 500.00 |
+----+------+--------+
Assume we need to the user latest 7days record, we have to filter by uid and sort it! so I want to redesign a table like below structure:
+----+---+------+-------+
| id |pid|uid | money |
+----+---+------+-------+
| 1 | 1 | 101 | 200.00 |
| 2 | 2 | 101 | 100.00 |
| 3 | 1 | 102 | 300.00 |
| 4 | 3 | 101 | 300.00 |
| 5 | 2 | 102 | 500.00 |
+----+---+-----+--------+
I just want to set a auto increment based on the uid. Example, if we already has store 101 on table, the pid will be incre 1 otherwise set 1. How can i reach this goal?