sql - Count column in mysql -


provided have table in mysql:

userid, paymentid, datetime blah, 123, 1/2/2011 blah, 144, 1/8/2011 foo, 151, 2/4/2011 bar, 178, 2,8,2011 

how can add 'order' column, sequence count per user, ordered datetime?

userid, paymentid, datetime, order blah, 123, 1/2/2011, 1 blah, 144, 1/8/2011, 2 foo, 151, 2/4/2011, 1 bar, 178, 2,8,2011, 1 

select userid, paymentid, datetime,         grptotal `order` (   select  userid,           paymentid,           datetime,           @sum := if(@grp = userid,@sum,0) + 1 grptotal,           @grp := userid      tablename,           (select @grp := '', @sum := 0) vars   order    userid, datetime ) x 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -