I'll do my best to describe what I need; hopefully, my description is clear.
I have a table containing a group of records with 2 fields upon which i need to sort.
record_no (integer and primary key)
and
cust_id (varchar - data set contains duplicates)
In a nutshell I need a result sorted such the I get the record with the lowest record_no of each cust_id, then the second lowest record_no of each cust id, etc, meaning that the result will have the duplicate cust_id's evenly distributed throughout the result, In other words, if the cust_id of the lowest record_no was "Al", and there were 300 distinct cust_id's the result would position "Al" as the first record, and again at the 301st position and so on until the result was complete. The actual number of occurrences for each distinct cust_id varies.
I hope I have described my predicament clearly. I would expect to abandon the original record_no in lieu of an auto_increment integer in the result table.
Can I do this in MySQL or do I need to loop a number of queries in PHP to do this?
Thanks for suggestions,
-Allen M.
I have a table containing a group of records with 2 fields upon which i need to sort.
record_no (integer and primary key)
and
cust_id (varchar - data set contains duplicates)
In a nutshell I need a result sorted such the I get the record with the lowest record_no of each cust_id, then the second lowest record_no of each cust id, etc, meaning that the result will have the duplicate cust_id's evenly distributed throughout the result, In other words, if the cust_id of the lowest record_no was "Al", and there were 300 distinct cust_id's the result would position "Al" as the first record, and again at the 301st position and so on until the result was complete. The actual number of occurrences for each distinct cust_id varies.
I hope I have described my predicament clearly. I would expect to abandon the original record_no in lieu of an auto_increment integer in the result table.
Can I do this in MySQL or do I need to loop a number of queries in PHP to do this?
Thanks for suggestions,
-Allen M.