mysql - How to number Duplicate rows in sql -
i'm trying figure out best/easiest way number duplicate rows accordingly.i have set of info uploading database table. have uploaded it, , auto incremented it, want generate order_id in fashion shown in question. example
----id-------name-----------order_id---------- 1 bob smith 1 2 steve jones 2 3 bob smith 1 4 billy guy 3 5 steve jones 2 ----------------------------------------------
i thinking utilize statement such select name table name= duplicate_name
can't seem figure out how realistically go that, much less come in appropriate order_id
afterwards. there easy way ?
you this:
select a.id, a.name, (select top 1 t.id table t t.name = a.name order t.id) order_id table
if database engine not back upwards top keyword, back upwards limit keyword, may able this:
select a.id, a.name, (select t.id table t t.name = a.name order t.id limit 1) order_id table
mysql sql database greatest-n-per-group row-number
No comments:
Post a Comment