I'm trying to sort the following table:
Table: People
+---+----------------------+
|id | Ethnicity |
+---+----------------------+
| 1 | 'Hispanic' |
| 2 | 'Asian American' |
| 3 | 'White' |
| 4 | 'African American' |
| 5 | 'American Indian' |
| 6 | 'Other' |
+---+----------------------+
SQL Query
SELECT DISTINCT Ethnicity FROM People ORDER BY Ethnicity ASC
Results
This generates:
+----------------------+
| Ethnicity |
+----------------------+
| 'American Indian' |
| 'Asian American' |
| 'African American' |
| 'Hispanic' |
| 'White' |
| 'Other' |
+----------------------+
The results I want to generate a开发者_运维技巧re:
+----------------------+
| Ethnicity |
+----------------------+
| 'African American' |
| 'American Indian' |
| 'Asian American' |
| 'Hispanic' |
| 'Other' |
| 'White' |
+----------------------+
Not sure what I'm doing wrong here.
If the data type is an enum, I believe it will order by the item's position (index) in the enum list, not the value of the enum string. Is "American Indian" the first item in your enum definition?
精彩评论