特殊的SQLite排序顺序Swift 3

时间:2017-08-24 02:28:42

标签: sqlite uitableview swift3

我希望有一个排序的常用名称数组。它们很容易在SQLite中按

排序
`...ORDER BY RL_Species.species ASC`

然而,并非每个物种都有一个共同的名称,因此有许多记录都没有“通用名称”。我想对所有常用名称ASC进行排序,但所有“无常用名称”都在排序列表的底部。

在TableViewController中使用基本代码调用它:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let cell: UITableViewCell       = tableView.dequeueReusableCell(withIdentifier: Resource.SpeciesCell)!

    let specieCommonName: UILabel   =         
            speciesCommonName.text   = self.species[(indexPath as NSIndexPath).row].commonName


    return cell
}

这可能吗?

1 个答案:

答案 0 :(得分:2)

请尝试以下查询:

SELECT * FROM `TABLENAME` ORDER BY case when RL_Species.species='no common name' then 1 else 0 end,RL_Species.species ASC