码迷,mamicode.com
首页 > 数据库 > 详细

yii2 Query Builder 查询打印sql语句

时间:2019-12-21 14:04:00      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:查询   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());

yii2 Query Builder 查询打印sql语句

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

原文地址:https://www.cnblogs.com/indifferent/p/12076428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!