Numbering Rows on Output
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? Thanks! Hal -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Numbering Rows on Output
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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Numbering Rows on Output
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:[EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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! Hal -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]