in reply to DBI efficient loop?
I don't understand your data manipulation requirements. It would be better if you edit your post to put your code in between <code>...</code> tags.
I think you could save a lot of work by pushing the data manipulation into the database instead of running a loop in Perl to do the data manipulation. If you need the count of FIELD1 that are equal, that's just some basic SQL:
select field1, count(*) from mytable group by field1
Your other query seems to have some more convoluted logic, but if you can reformulate it in a more descriptive than prescriptive way, it will be translatable to SQL far more easy. You use vocabulary like "loop until find a valid entry", which I guess means "not equal to '-'". My guess at it is the following, but I'm unclear on whether you want to actually manipulate the data or just return a result:
select field1 from mytable l where field2 <> '-' order by field1, field2
or, if you only want all the "first" rows of field1 where field2 is not '-', then maybe the following returns what you need:
select field1, min(field2) from mytable l where field2 <> '-' group by field1 order by field1, field2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI efficient loop?
by lorenzov (Novice) on Jun 11, 2008 at 11:04 UTC |