yii2 ActiveRecord通过计算查找OrderBy

时间:2016-01-04 10:15:58

标签: php mysql activerecord yii2

尝试从我的数据库中获取描述。 查询返回结果,但我想命令结果只显示投票率最高的那个。

投票应按pi@raspberrypi:~ $ ffmpeg -s 320x240 -f video4linux2 -i /dev/video0 -f mpeg1video -b 800k -r 30 http://localhost:8082/mypassword/320/240/ ffmpeg version N-77221-g93d336f Copyright (c) 2000-2015 the FFmpeg developers built with gcc 4.9.2 (Raspbian 4.9.2-10) configuration: --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree libavutil 55. 10.100 / 55. 10.100 libavcodec 57. 17.100 / 57. 17.100 libavformat 57. 20.100 / 57. 20.100 libavdevice 57. 0.100 / 57. 0.100 libavfilter 6. 21.100 / 6. 21.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 [video4linux2,v4l2 @ 0x1d4b230] The device does not support the streaming I/O method. /dev/video0: Function not implemented 列减去的upvoted列进行计算

downvoted

我希望有人可以编写这部分查询 - 谢谢

1 个答案:

答案 0 :(得分:26)

你应该试试:

$description = UnitDescription::find()
    ->where(['id_unit' => $model->id])
    ->orderBy(['(upvoted - downvoted)' => SORT_DESC])
    ->one();