标签:查询 query orderby cat where one table _id ges
$query = new Query();
$query->select(‘gs.*, g.goods_images, sa.attr_name, sa.is_default, sa.alias_sort‘)->from(GoodsSpec::tableName() . ‘ gs‘);
$query->leftJoin(SpecAlias::tableName() . ‘ sa‘, ‘gs.attr_id = sa.attr_id and gs.goods_id = sa.goods_id‘);
// $query->leftJoin(CatSpec::tableName() . ‘ c‘, ‘gs.attr_id = c.attr_id and gs.cat_id = c.cat_id‘);
$query->leftJoin(AttrValue::tableName() . ‘ av‘, ‘gs.attr_vid = av.attr_vid‘);
$query->leftJoin(Goods::tableName() . ‘ g‘, ‘g.goods_id = gs.goods_id‘);
$query->andWhere(‘gs.goods_id in (‘.$goods_ids.‘)‘);
// $query->groupBy([‘gs.goods_id‘]);
$query->orderBy([
‘sa.is_default‘ => SORT_DESC,
‘gs.spec_sort‘ => SORT_ASC,
‘av.attr_vsort‘ => SORT_ASC
]);
$sql = clone $query;
var_dump($sql->createCommand()->getRawSql());
标签:查询 query orderby cat where one table _id ges
原文地址:https://www.cnblogs.com/indifferent/p/12076428.html