mysql>
mysql> SELECT NUMBER AS SQUARE, ROUND(SQRT(NUMBER)) AS BASIS
-> FROM (SELECT CAST(CONCAT(DIGIT1.DIGIT,
-> CONCAT(DIGIT2.DIGIT,
-> DIGIT3.DIGIT)) AS UNSIGNED INTEGER)
-> AS NUMBER
-> FROM (SELECT '0' AS DIGIT UNION SELECT '1' UNION
-> SELECT '2' UNION SELECT '3' UNION
-> SELECT '8' UNION SELECT '9') AS DIGIT1,
-> (SELECT '0' AS DIGIT UNION SELECT '1' UNION
-> SELECT '2' UNION SELECT '3' UNION
-> SELECT '8' UNION SELECT '9') AS DIGIT2,
-> (SELECT '0' AS DIGIT UNION SELECT '1' UNION
-> SELECT '2' UNION SELECT '3' UNION
-> SELECT '8' UNION SELECT '9') AS DIGIT3)
-> AS NUMBERS
-> WHERE SQRT(NUMBER) = ROUND(SQRT(NUMBER))
-> ORDER BY NUMBER;
+--------+-------+
| SQUARE | BASIS |
+--------+-------+
| 0 | 0 |
| 1 | 1 |
| 9 | 3 |
| 81 | 9 |
| 100 | 10 |
| 121 | 11 |
| 289 | 17 |
| 900 | 30 |
+--------+-------+
8 rows in set (0.00 sec)
mysql>