VFP 中是否有替代 MySQL Field() 函数的方法?

Is there an alternative to MySQL Field() function in VFP?

我有一个包含“国家/地区”列的多字段 table。我喜欢查询的结果首先按特定国家/地区排序,然后按字母顺序排序。在 MySQL 我会做这样的事情:

Select * from myTable Order By Field(Countries,'Italy'),Countries

在 Visual-FoxPro 中,我已尝试索引由该查询创建的 Cursor:

Select * from myTable Order By Countries

Index on Countries<>'Italy' TAG test

这将首先显示 'Italy' 的所有结果,但将其余结果按不可预测的 table 顺序显示。 如何在 Visual-FoxPro 中实现?

在 VFP 中,你可以用这样的方式来完成:

SELECT * FROM myTable WHERE Countries='Italy' ;
UNION ALL ;
SELECT * FROM (SELECT * FROM myTable WHERE Countries<>'Italy' ORDER BY Countries) as secsel

它确实按 "if countries is not Italy first then Italy"、国家/地区排序。对吗?

在 VFP 中,您可以使用 IIF()。即:

Select *, iif(Countries == 'Italy', 1, 0) as CItaly ;
 from myTable :
 Order By CItaly,Countries

注意:如果您想通过索引执行此操作,则可以使用复合索引,例如:

index on iif(Countries = 'Italy', '1', '0') + Countries tag myCountry