List:General Discussion« Previous MessageNext Message »
From:Hal Vaughan Date:November 28 2005 9:54pm
Subject:Re: Numbering Rows on Output
View as plain text  
On Monday 28 November 2005 04:45 pm, Dan Nelson wrote:
> In the last episode (Nov 28), Hal Vaughan said:
> > I have a table that lists the tasks a program has to do.  Lately I've
> > found I can have an "at-a-glance" status report of how things are
> > going on by writing a loop (in bash scripting, on Linux, btw) that
> > uses "mysql -e" to display the list of tasks and their current state.
> > It's quick and a lot simpler than I thought it would be to create a
> > self-updating status display.
> >
> > The only thing missing is that it would be helpful to be able to add
> > an extra column on the left for a row count -- preferably so each
> > selected row has a number beside it, but putting a summary count on
> > the last line (or adding an extra line with a summary count below it)
> > would be helpful.
> >
> > I've Googled, but it seems this is almost impossible to do.  Is it?
> > Or is there a simple way to have a count next to the rows being
> > displayed?
> SET @row=0;
> SELECT @row:=@row+1 AS row, otherfields from mytable;
> If you're doing it with mysql -e, this does it with one command:
> SELECT @row:=(ifnull(@row,0))+1 AS row, otherfields from mytable;

Actually, this kept printing 1 for each row, so I did this:

mysql -e "SET @row=0; SELECT @rwo:=@row+1 AS Row..."

which, obviously, is using the first way, but setting the variable in the same 
command line in "mysql -e".  That worked perfectly!

It's interesting how there were so many pages on the net that indicated this 
was not possible or easily done.

Thank you!

Numbering Rows on OutputHal Vaughan28 Nov
  • Re: Numbering Rows on OutputDan Nelson28 Nov
    • Re: Numbering Rows on OutputHal Vaughan28 Nov