Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If it was simply columns A-Z, then this is a simple answer</p> <pre><code>SELECT celldata, SUBSTR(cellposition,1,2) AS column, SUBSTR(cellposition,2) AS row, cellposition FROM mytable ORDER BY 3,2 </code></pre> <p>It gets a bit harder when you might have additional columns like 'AA', 'AZ', 'BA', etc... not just to extract the column/row; but also to handle the column ordering... I'm still working on a solution for that. Without actually writing it all out, I'd do a CASE test on the 2nd, 3rd, 4th characters of cellposition testing for a numeric value, and adjust the SUBSTR offset and length accordingly to split the row and column components, and then use LPAD() to pad the column with spaces to 3 characters length.</p> <p>If you can extend your MySQL, then <a href="https://github.com/mysqludf/lib_mysqludf_preg" rel="nofollow">LIB_MYSQLUDF_PREG</a> provides additional PREG_CAPTURE and PREG_POSITION functions in MySQL that would make this a lot easier; but you need to recompile MySQL from source to do this. The MySQL developers really should consider implementing this as standard.</p> <p>It's actually a lot easier in PHP as you can simply retrieve the records in any order, then usort() in PHP and handle the splitting there using something like:</p> <pre><code>list($c,$r) = sscanf($coord,'%[A-Z]%d'); $c = str_pad($c, 3, ' ', STR_PAD_LEFT); </code></pre> <p>to split row/col and adjust col to a comparable string by padding it; but that could be painfully memory-expensive if you're working with large volumes of data.</p> <p>I used an array keyed on the cell address, and with the value as the cell value, so:</p> <pre><code>function cellAddressCompare($a, $b) { sscanf($a,'%[A-Z]%d', $ac, $ar); sscanf($b,'%[A-Z]%d', $bc, $br); if ($ar == $br) { return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); } return ($ar &lt; $br) ? -1 : 1; } uksort ($testArray, 'cellAddressCompare'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload