On 10/14/2015 5:20 PM, Don V Nielsen wrote:
> X has columns zip & crrt, just like crrt_net_non.  These form a composite
> key identifying groups within x.  A value "53001.R501" would be an
> example...53001 being the zip code and R501 being the carrier route.  There
> are 52 rows in X that have the key 53001.R501.  A calculation determined
> that I need 42 rows from that key and saved the result in crrt_net_non, the
> row looking like "53001.R501.52.6.46.42".  What I need is a sql function
> that can iterate over crrt_net_non, then grab the rows from X, "53001.R501"
> being first key, sort them into an internal group sequence, then update a
> code of the first 42 rows of that sorted group, and then doing this until
> crrt_net_non is exhausted.

Are you looking for something like this?

UPDATE X set code=whatever where rowid in (
   select x2.rowid from X x2 where X.zip=x2.zip and X.crrt=x2.crrt
   order by someOrder
   limit ifnull( (
      select net_non_pieces from crrt_net_non net
      where X.zip=net.zip and X.crrt=net.crrt
   ), 0)
);

-- 
Igor Tandetnik

Reply via email to