List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:November 28 2005 9:45pm
Subject:Re: Numbering Rows on Output
View as plain text  
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;

-- 
	Dan Nelson
	dnelson@stripped
Thread
Numbering Rows on OutputHal Vaughan28 Nov
  • Re: Numbering Rows on OutputDan Nelson28 Nov
    • Re: Numbering Rows on OutputHal Vaughan28 Nov