sql - MySQL row numbers for table -


i trying row numbers table. far sql prompt:

select @i = @i + 1 rank, x.name, x.partyname, x.constituencyname, x.votes  (     select concat(t1.firstname, ' ', t1.lastname) name, t1.partyname, t1.constituencyname, coalesce(t2.count, 0) votes         (             (select db.user.pid, db.user.firstname, db.user.lastname, db.party.partyname, db.constituency.constituencyname                  db.user                 left join db.party on db.user.partyid = db.party.partyid                  left join db.constituency on db.user.cid = db.constituency.cid                 db.user.partyid not null                 , db.user.cid not null             ) t1             left join             (select db.user.vote, count(*) 'count'                  db.user                  group db.user.vote             ) t2         on             t1.pid = t2.vote         order t2.count desc)         ) x, (select @i:=1) r 

so that, first create table t1(that gets information 2 different tables) , join table t2 can every candidate total votes. have marked table 'x' , joined table 'r' should initialise row numbers(used online tutorial row numbers). when run sql prompt following in return:

rank    name    partyname   constituencyname    votes 0       name1   party1      constituency1       700 0       name2   party1      constituency1       550 

any suggestions appreciated.

this user variable , should use := not =

select @i := @i + 1 rank,... 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -