eli22
Programmer
- Oct 20, 2014
- 3
Hi. I have a field which might come in as a numeric but it's usually character. It might have numbers in it. And I use that field to define groups for processing.
Until now this has been my query to define the groups
SELECT myfield FROM mytable GROUP BY 1
But when there are many numerically-named groups, they show up out of order:
1
10
2
3
etc.
I want to change the query to
SELECT VAL(myfield) FROM mytable GROUP BY 1
But then the group names become numeric - we want character group names.
Is there a way to add an ORDER BY clause to the original query, that sorts according to the numeric value? I didn't have luck with that. This would also be better because if I get data like: 1tree, 2tree, 3tree, 4tree, then I can sort it also. (I'll add a test whether the field actually has a numeric or not before sorting it this way, and when it doesn't I'll use the old query.)
Thank you,
Ellen
Until now this has been my query to define the groups
SELECT myfield FROM mytable GROUP BY 1
But when there are many numerically-named groups, they show up out of order:
1
10
2
3
etc.
I want to change the query to
SELECT VAL(myfield) FROM mytable GROUP BY 1
But then the group names become numeric - we want character group names.
Is there a way to add an ORDER BY clause to the original query, that sorts according to the numeric value? I didn't have luck with that. This would also be better because if I get data like: 1tree, 2tree, 3tree, 4tree, then I can sort it also. (I'll add a test whether the field actually has a numeric or not before sorting it this way, and when it doesn't I'll use the old query.)
Thank you,
Ellen