按照Laravel 5.3中两列的差异排序

时间:2016-12-26 19:18:39

标签: php laravel laravel-5 eloquent laravel-5.3

我有一个雄辩的查询,其中orderBy之一是两列的差异。

if let playerView = self.playerView {
    let playerItem = AVPlayerItem(url: self.url)
    let player = AVPlayer(playerItem: playerItem)

    let playerVc = AVPlayerViewController()
    playerVc.player = player

    self.addChildViewController(playerVc)
    playerVc.view.frame = playerView.bounds
    playerView.addSubview(playerVc.view)
    playerVc.didMove(toParentViewController: self)

    player.play()
}

使用sqlite的localhost上完全相同的代码可以正常运行而不会出现错误。但是在使用MySQL生产时出现以下错误

$mymodel = Level::where([['ColA', 5], ['ColB', 10], ['ColC', 7]])
                 ->orderBy('ColA', 'Desc')
                 ->orderBy('ColA' - 'ColB', 'Desc')
                 ->orderBy('ColC', 'Desc')
                 ->orderBy('ColD', 'Asc')
                 ->pluck('userId')->toArray();

1 个答案:

答案 0 :(得分:9)

$model = Level::where($wheres)
              ->orderByRaw('(ColA - ColB) DESC')
              ->pluck('userId')
              ->toArray();