当前位置:Gxlcms > 数据库问题 > yii2 Query Builder 查询打印sql语句

yii2 Query Builder 查询打印sql语句

时间:2021-07-01 10:21:17 帮助过:17人阅读

$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());

yii2 Query Builder 查询打印sql语句

标签:查询   query   orderby   cat   where   one   table   _id   ges   

人气教程排行