如果在 select 查询中使用别名,如何计算所有记录?
How to count all records if use alias in select query?
我将 Sphinx 与 Yii2 一起使用,需要通过 jSON 字段进行筛选。
$query = new \yii\sphinx\Query();
$query->from('announcements');
$query->addSelect("*");
$query->addSelect(new Expression("IN(filters['color'], 'blue', 'red', 'green') AS f_color"));
$query->where("is_active = 1");
$query->andWhere("f_color = 1");
$announces = $query->all();
我的 Sphinx 索引中有 jSON 个字段 filters
。例如:
[filters] => {"brand":"Toyota","model":"Prius","color":"red","price":"12000"... etc]
它工作正常。但是现在我需要做一个分页...当我尝试计算 $query->all()
之前的记录时出现问题
$count = $query->count(); // Return error "no such filter attribute 'f_color'"
生成的查询是:
SELECT COUNT(*) FROM announcements WHERE ( is_active = 1 ) AND ( f_color = 1 )
我将 Sphinx 与 Yii2 一起使用,需要通过 jSON 字段进行筛选。
$query = new \yii\sphinx\Query();
$query->from('announcements');
$query->addSelect("*");
$query->addSelect(new Expression("IN(filters['color'], 'blue', 'red', 'green') AS f_color"));
$query->where("is_active = 1");
$query->andWhere("f_color = 1");
$announces = $query->all();
我的 Sphinx 索引中有 jSON 个字段 filters
。例如:
[filters] => {"brand":"Toyota","model":"Prius","color":"red","price":"12000"... etc]
它工作正常。但是现在我需要做一个分页...当我尝试计算 $query->all()
$count = $query->count(); // Return error "no such filter attribute 'f_color'"
生成的查询是:
SELECT COUNT(*) FROM announcements WHERE ( is_active = 1 ) AND ( f_color = 1 )